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: Sintu Raj UID:21BCS1147
BRANCH: B.E.CSE SECTION:601-B
SEMESTER: 4th D.O.P:24/03/2023
SUBJECT: Programming in Python Lab(21CSP-259)
---------------------------------------------------------------------------------------------------

Aim: Python programs to demonstrate the various kind of operations


that can be applied to the list.

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.
Source code:
def Sort_Tuple(list):
list.sort(key=lambda x: x[-1])
return list
list = [(1, 3), (3, 2), (2, 1)]
print(Sort_Tuple(list))

Output:

C:\Users\sintu\AppData\Local\Programs\Python\Python311\p
ython.exe "C:\Users\sintu\python\list2.2(i).py"
[(2, 1), (3, 2), (1, 3)]

Process finished with exit code 0


DEPARTMENT OF
COMPUTER SCIENCE &ENGINEERING
2. Write a python program to print a specified list after removing the
0th,4th and 5th elements.

Source code:
list=['Red', 'Green', 'White', 'Black', 'Pink',
'Yellow']
t=len(list)
print(t)
del list[5]
del list[4]
del list[0]
print(list)

Output:

C:\Users\sintu\AppData\Local\Programs\Python\Python311\p
ython.exe C:\Users\sintu\python\2.2Qb.py
6
['Green', 'White', 'Black']

Process finished with exit code 0

You might also like