You are not logged in.
I wrote a small python-script in order to do some manipulation of columns. I'm quite unexperienced, and i stumbled upon a problem i didn't manage to solve:
When the script is finished with the data manipulation, everything is stored as data type "list", which implies the following form when i output the data with print: ['2321321', '321321321', '55555']. I don't want the brackets and ' (since i want to import the data into a spreadsheet). I've tried to make a loop to print out list content, but then i get everything in one column, which i don't want. (Something like: for l in line: print l )
Is there a way to print lists without the brackets and '? I tried to solve it with sed, but my knowledge of that program is zero, and no success. My solution was to open the output in a text editor and use search and replace, which is very tedious work for 50 files.
Offline
I *know* there's a better way! I just cant remember it right now, but in the meantime this should work.
list = ["some","cool","list","of","stuff"]
biglist = ""
for item in list:
biglist = biglist + item
print biglist
Offline
I think the quicker way is using the join() method:
[andyr@roo ~]$ python
Python 2.4.1 (#1, Apr 5 2005, 11:00:51)
[GCC 3.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> items = ["one", "two", "three"]
>>> allitems = " ".join(items)
>>> print allitems
one two three
Of course, you could have "," or "t" (tabs), etc to delimit the columns rather than the space in the above example.
Offline
I think the quicker way is using the join() method:
Of course, you could have "," or "t" (tabs), etc to delimit the columns rather than the space in the above example.
damn! i knew there was! i just couldnt remember, and was too lazy to read the docos.
iphitus
Offline
yeah. and in addition, you can suppress newlines with print, by adding a comma after the statement, if I remember correctly..
print i,
"Be conservative in what you send; be liberal in what you accept." -- Postel's Law
"tacos" -- Cactus' Law
"t̥͍͎̪̪͗a̴̻̩͈͚ͨc̠o̩̙͈ͫͅs͙͎̙͊ ͔͇̫̜t͎̳̀a̜̞̗ͩc̗͍͚o̲̯̿s̖̣̤̙͌ ̖̜̈ț̰̫͓ạ̪͖̳c̲͎͕̰̯̃̈o͉ͅs̪ͪ ̜̻̖̜͕" -- -̖͚̫̙̓-̺̠͇ͤ̃ ̜̪̜ͯZ͔̗̭̞ͪA̝͈̙͖̩L͉̠̺͓G̙̞̦͖O̳̗͍
Offline
Thanks, folks!
I haven't tried it yet, but i'm sure this is what i need!
EDIT: Now i have - perfect!
Offline