Light Mode
Dark Mode
sort()

Hello all!

Since i am started learn oython there is tons of questions in my mind:) Here is a simple for loop code ;

list = [4, 5, 7, 8, 9, 1, 0, 7, 10, 5]
list.sort() 
prev = None
for item in list:
    if prev == item:
        print("Duplicate of", prev,"found")
    prev = item

Questions are : #Why there is list.sort() under list? What if i dont want sort it? By the way if you remove this code program doest show results.

and why in end of the code there is "prev = item" ?

Thank you a lot!

Created: Oct. 4, 2014, 1:51 a.m.
Updated: Oct. 4, 2014, 2:40 a.m.
0
1
User avatar
ErkinOner