I've just started using python in my computer technology class. One thing I can't figure out is how to have python put the lists inside a string into alphabetical order. If anyone has any easy answer, it will be much appreciated. Also, my teacher told me he would give extra credit if I use bubblesort.
pinbustersrule 0 Unverified User
Recommended Answers
Jump to PostI don't understand your question entirely, but there is a Python snippet at:
http://www.daniweb.com/code/snippet452.html
that looks at various sorting algorithms, including the ever so slow bubblesort.
Jump to PostIt's your extra credit, not mine. You'll have to come up with some code to start with or at least some ideas.
Jump to PostIn terms of putting items into a list to be sorted, you want this:
f = open("mytextfile","r") mylist = [] for line in f: mylist.append(f.readline()) f.close()
or even more concisely,
f = open("mytextfile","r") lines = f.readlines() f.close()
I agree with woooee, but he's not …
All 9 Replies
vegaseat 1,735 DaniWeb's Hypocrite Team Colleague
pinbustersrule 0 Unverified User
pinbustersrule 0 Unverified User
woooee 814 Nearly a Posting Maven
pinbustersrule 0 Unverified User
woooee 814 Nearly a Posting Maven
pinbustersrule 0 Unverified User
jrcagle 77 Practically a Master Poster
noonecares 0 Newbie Poster
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.