0% found this document useful (0 votes)
22 views2 pages

Python 2.2 - Sintu

The document contains instructions and code for two Python programs that demonstrate operations on lists. The first program sorts a list of tuples in increasing order based on the last element of each tuple. The second program removes the 0th, 4th, and 5th elements from a specified list and prints the resulting list. Both programs output the expected sorted/modified lists, demonstrating common list operations in Python.

Uploaded by

Jgapreet Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views2 pages

Python 2.2 - Sintu

The document contains instructions and code for two Python programs that demonstrate operations on lists. The first program sorts a list of tuples in increasing order based on the last element of each tuple. The second program removes the 0th, 4th, and 5th elements from a specified list and prints the resulting list. Both programs output the expected sorted/modified lists, demonstrating common list operations in Python.

Uploaded by

Jgapreet Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 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