I have been working on something, and i'm stuck again...
I have to print out an infile list in columns, and then print it out again in alphabetical order(sort). I can't figure how to print in columns, nor can i soft it. Any help?

\t will print a tab. I don't know if that's your best option, not seeing your data.

Member Avatar for leegeorg07

use a for loop e.g.

mylist = ['a', 'b', 'c', 'd']
for word in mylist:
    print word

outputs

a
b
c
d

Each row is considered a line of text. In order to get a line of text you need a string, here's how i would do it, if i wanted to print to console the way you want it to look.

simple way:

>>> mylist = ['a', 'b', 'c', 'd']
>>> print ''.join(mylist) #ugly code
abcd

better way:

>>> import string
>>> print string.join(mylist, '')
abcd

Inefficient way, repetition of code:
If the function is already optimized twice in the above examples, why would you loop through it yourself

string = ''
for item in mylist:
    string = string + item + ''
print string

I'm importing a file of around 30 names, and then sorting it. I guess my hang up is not being able to see the list and still sorting it.
I'll get some of my code later for a better example.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.