Document 1

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

DEPARTMENT OF

COMPUTER SCIENCE &


ENGINEERING

WORKSHEET 2.2

Student Name: Suhani nayak UID: 21BET1061


Branch: BE - IT Section/Group:601B
Semester: 4th Date of Performance:6-04-23
Subject Name: Python Lab Subject Code:21ITH-259

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)

tuples_list = [(1, 3), (3, 2), (2, 1), (5, 4)]


ENGINEERING
sorted_list = sort_tuples(tuples_list)
print(sorted_list)

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']

my_list = ['Red', 'Green', 'White', 'Black', 'Pink', 'Yellow']

# Remove the 0th, 4th, and 5th elements


del my_list[5]
del my_list[4]
del my_list[0]

# Print the updated list


print(my_list)

4. OUTPUT:

a)

b)

You might also like