Hey, please how can i logically sort for numbers in a list
list = [10, 5, 2, 7, 20]
without the sort()
using only if statements and for loops and no while loop.
Subomi
0
Newbie Poster
Recommended Answers
Jump to PostIt's very ineffient but here goes:
a= [10, 5, 2, 7, 20] b=[] for i in xrange(len(a)): b.append(min(a)) a.pop(a.index(b[-1]))
Jump to PostHere is a sorting method called bubble sort, the best way to learn is try and do it yourself even if you fail. This is wrote in pseudo code so you can impliment it into python.
define MyFunction (list): for OuterForLoopCounter in 1 to listlength-1: for InnerForLoopCounter …
All 8 Replies
rrashkin
41
Junior Poster in Training
Subomi
0
Newbie Poster
Lardmeister
461
Posting Virtuoso
slate
241
Posting Whiz in Training
Subomi
0
Newbie Poster
aVar++
14
Posting Whiz
aVar++
14
Posting Whiz
vegaseat
1,735
DaniWeb's Hypocrite
Team Colleague
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.