yadin wrote:
Good day every one!

I got this python program that returns me a set like this..
Set ([‘A\n’, B\n’, ‘C\n’, ‘D\n’, ‘E\n’, ‘F\n’, ‘G\n’ ])
And a list pp =‘100\n’ ‘200\n’ ‘300\n’ ‘400\n’]
I was reading this from a file….
How can I transform this to something that looks like this
Column1 Column 2

  100              A
   200             B
   300             C
    400            D
             E
             F
                     G
And then write this to a file???
thank you for taking your time!!!


Since a set has no order, it cannot be done. There's no association between 100 and A that can be independently determined from just the set and the list.

Just how was the original assignment worded, anyway? And what version of Python are you using for it?

After you solve that problem (perhaps by returning a list in both cases), then the real question might be one of formatting.


Since the columns in your example don't line up in any meaningful way, perhaps you just want to slap a few spaces before and between the elements. You'll need to do a strip() on the pp items, to get rid of the newline. Then something like:
line = " " + ppitem.strip() + " " + otheritem

Loop through the lists and send the lines to the file. Don't forget to close it at the end.


--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to