You need to convert that iterator to a list.
unsorted = range(10)
unsorted_list = list(unsorted)
After this, your code will sort in descending order because you are making a swap if tuple_list[cnt]
is less than tuple_list[cnt+1]
. If you change the logical operator from "<
"to ">
" you will get ascending order because after changing, you will make swaps if tuple_list[cnt]
is greater than tuple_list[cnt+1]
By naming your list as tuple_list, it is kind of confusing. Because in python lists and tuples are different.
What's the difference between lists and tuples?