Professional Documents
Culture Documents
Divyansh Python 2.2
Divyansh Python 2.2
WORKSHEET 2.2
Aim:
Q1. Write a Python program to get a list, sorted in increasing order by the last
element in each tuple from a given list of non-empty tuples.
Q2.WAP to print specified list after removing 0, 4th and 5th elements. Sample list:
[ 'Red','Green','White','Black','Pink','Yellow']
Expected o/p: [ 'Green','White','Black' ]
Program Code:
1. Write a Python program to get a list, sorted in increasing order by the last
element in each tuple from a given list of non-empty tuples.
def sort_list_last(tuples):
return sorted(tuples, key=last)
print(sort_list_last([(2, 5), (1, 2), (4, 4), (2, 3), (2, 1)]))
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
OUTPUT
Program Code:
OUTPUT