I can't find anything to help me out on this method of sorting. How do I do it?
chris99
0
Junior Poster
Recommended Answers
Jump to PostYou can, for fun, choose sort algorithm, use list of words (strings) and use len() for comparison...
http://www.daniweb.com/code/snippet452.html
Then, if you have problems making it work you can post code, so we can see what is wrong ;)
Jump to PostOh, one of Vegaseat's brain teasers. There are several ways to solve this. If you look in the Python reference manual under sort for lists, you find that you can specify your own custom sort method. In this case it would be sorting by length of each word/string in the …
Jump to PostThere are several ways to do this.
First use a for loop, word.lower() and list2.append(word) to create a new list2 from list1 with all lower case words.
Now you can convert list2 to a set with set1 = set(list2) which by design has only unique words. Convert this …
Jump to PostIf anyone figures out a different way to sort by word length, or form a unique word list, please attach your code to this thread! Would be fun to see your ideas!!!!!
Jump to PostOne word of advice right away:
"Do not use list as a variable name since list is a function in Python!"Use listA or something like that:
listA = ['Herring','used','to','be','abundant','in','the','Atlantic','Ocean','then','herring','got','overfished'] # start with an empty list listB = [] # go through each word in listA …
All 18 Replies
Micko
2
Junior Poster
chris99
0
Junior Poster
Ene Uran
638
Posting Virtuoso
chris99
0
Junior Poster
Ene Uran
638
Posting Virtuoso
Ene Uran
638
Posting Virtuoso
chris99
0
Junior Poster
Ene Uran
638
Posting Virtuoso
chris99
0
Junior Poster
ghostdog74
57
Junior Poster
vegaseat
1,735
DaniWeb's Hypocrite
Team Colleague
Ene Uran
638
Posting Virtuoso
vegaseat
1,735
DaniWeb's Hypocrite
Team Colleague
deeplavi
0
Newbie Poster
Taraka Rama
0
Newbie Poster
farmwife
0
Light Poster
vegaseat
1,735
DaniWeb's Hypocrite
Team Colleague
farmwife
0
Light 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.