How would i sort this list, based on the integer inside the 2nd list?
import random
l= []
for i in range(10):
l.append(['xyz', random.randint(1,100)])
print(l)
Thank you!
How would i sort this list, based on the integer inside the 2nd list?
import random
l= []
for i in range(10):
l.append(['xyz', random.randint(1,100)])
print(l)
Thank you!
In [13]: l.sort(key=operator.itemgetter(1))
In [14]: l
Out[14]:
[['xyz', 6],
['xyz', 7],
['xyz', 17],
['xyz', 41],
['xyz', 52],
['xyz', 54],
['xyz', 62],
['xyz', 66],
['xyz', 68],
['xyz', 69]]