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

DEPARTMENT OF

COMPUTER SCIENCE & ENGINEERING

WORKSHEET 2.2

StudentName: DIVYANSH BHARGAV UID:21BCS4937


Branch: CSE Section/Group: 616-A
Semester: 4th Date of Performance: 20/03/2023
Subject Name: PROGRAMMING IN PYTHON LAB
Subject Code: 21CSP-259

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 last(n): return n[-1]

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:

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

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


color = [x for (i,x) in enumerate(color) if i not in (0,4,5)]
print(color)

OUTPUT

You might also like