Skip to content Skip to sidebar Skip to footer

Trying To Print A List In Reverse?

I am trying to print this list in descending order however this is not working any ideas why? l = ['Germany',3,2,10,'Italy',7,9,1,'canada',4,5,3,'china',4,3,9] d_list = [] for i in

Solution 1:

print [i for i inreversed(l)]

because reversed returns an iterator, so it wouldn't be enough to just print reversed.

Or what does descended order mean here for you?

Solution 2:

Another option would be to reverse the entire list, then print it.

l[::-1]
for x in range(len(l)):
    print(l[x-1])

Post a Comment for "Trying To Print A List In Reverse?"