Professional Documents
Culture Documents
Document 1
Document 1
Document 1
WORKSHEET 2.2
1. Aim:
Program to demonstrate creation and accessing of lists and apply different kinds
of operations on them.
2. Objective:
a) 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
b) Write a Python program to print a specified list after removing the 0th, 4th
and 5th elements, Sample List: ['Red', 'Green', 'White', 'Black', 'Pink', 'Yellow'],
Expected Output: ['Green', 'White', 'Black']
3. Program Code:
a) 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 last_element(tuple):
return tuple[-1]
def sort_tuples(tuples_list):
return sorted(tuples_list, key=last_element)
b) Write a Python program to print a specified list after removing the 0th, 4th
and 5th elements, Sample List : ['Red', 'Green', 'White', 'Black', 'Pink',
'Yellow'],Expected Output : ['Green', 'White', 'Black']
4. OUTPUT:
a)
b)