0% found this document useful (0 votes)
9 views5 pages

Revision

The document outlines various Python programming tasks involving lists and dictionaries, including operations such as extending lists, finding minimum values, modifying elements, and performing basic arithmetic. It also includes examples of how to manipulate dictionaries by adding, deleting, and retrieving values. Additionally, it provides specific outputs for certain code snippets to predict results based on given data.

Uploaded by

rizafatin07
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)
9 views5 pages

Revision

The document outlines various Python programming tasks involving lists and dictionaries, including operations such as extending lists, finding minimum values, modifying elements, and performing basic arithmetic. It also includes examples of how to manipulate dictionaries by adding, deleting, and retrieving values. Additionally, it provides specific outputs for certain code snippets to predict results based on given data.

Uploaded by

rizafatin07
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/ 5

Aman has created two lists L1=[6,2,3,8] and L2=[1,5,4]

He has been asked by his teacher to write the code for the following tasks:-

I. To predict the output of the code:-

L3=L2.extend(L1)

print(L3)

II. To display smallest number from L3

III. To add 2nd element from L1 and 3rd element from L2

IV. To arrange the elements of L3 in descending order

V. To predict the output : L1[:2]+L2[2:]


Raman has stored record of a student in a list as follows:-

rec=[‘Thomas’,’C-25’,[56,98,99,72,69],78.8]

Suggest him the Python statements to do the following tasks:-

a. To find the percentage

b. To find marks of 5th subject

c. Maximum marks of the student

d. To find total marks

e. To change the name from ‘Thomas’ to ‘ Charles’

Consider the following dictionary:

Alpha= {‘D’: ‘Delhi’, ‘K’: ‘Kite’, ‘T’: ‘Toy’, ‘B’: ‘Boy’}

Write Python statements for the following:

i) To insert (‘M’ : ‘Monkey’) in the dictionary.

ii) To return the value corresponding to the key ‘K’

iii) To return the length of the dictionary.

iv)To delete the item from the dictionary corresponding to the key ‘B’
Consider the following dictionary:

Alpha={‘D’: ‘Delhi’ , ‘K’ : ‘Kite’ , ‘T’ : ‘Toy’ , ‘B’ : ‘Boy’}

Write Python statements for the following:

i) Alpha[“M”]=”Monkey”

ii) print(Alpha[“K”])

iii) print(len(Alpha))

iv) del Alpha[“B”]


Consider the following dictionary:

name={1:”India”,2:‟australia‟,3:‟Japan‟,4:‟America‟,5:‟China‟}

Perform the below mentioned operations in the

dictionary:

i) Write command traverse a dictionary and print keys one by one

for i in name:

print(i)

ii) Write command to print values only.

print(name.values())

iii) Write command to add new element having key 6 and values as

“Ireland”

name[6]=”Ireland”

iv) Write command to change value of key 3 to “New

Zealand”

name[3]=”New Zealand”

v) write command to delete values Japan

del name[3]
consider the following dictionary: states={‘D’: ‘Delhi’ , ‘K’ : ‘Kerala’ , ‘T’ :

‘Tamil Nadu’ , ‘B’ : ‘Bihar’}

Write Python statements for the following:

a) To insert (‘M’ : ‘Mumbai’) in the dictionary states.

b) To return the value corresponding to the key ‘T’

c) To return the length of the dictionary states.

d) To delete the item from the dictionary corresponding to the key ‘K’

e) To delete the dictionary ‘states’

Consider the following dictionary:

d={1:‟One‟,3:‟Three‟,5,‟Five‟,7:‟Seven‟,9:‟N

ine‟} Perform the below mentioned operations

in the dictionary:

(a) Write command traverse a dictionary and print key & values

(b) ii) Write command to print only values of dictionary.

(c) Write command to delete the second last element of

dictionary.

(d) Write command to delete all elements of the dictionary

(e) v) write command to add another element with key as

33 and value 23

Predict the output based on the list, cod = [98, 45, 62, 14, 1007]

a) print(len(cod))

Ans :5

b) print(cod * 2)

Ans: [98, 45, 62, 14, 1007, 98, 45, 62, 14, 1007]

c) print(1007 in cod)
Ans: True

d)print(cod[:2]+cod[2:])

Ans : [98, 45, 62, 14, 1007]

e) cod=[98, 45, 62, 14, 1007, 1010]

print(cod. pop(1))

The record of a student is stored as a list in the following format(Name, Roll.No,

Marks in 3 subjects, Percentage)

RecordList = [‘Komal’, ‘A-19’, [71, 86, 72], 76.3]

Write Python statements to retrieve the following information from the list, RecordList

● Name of the student

● Mark in the first subject

● Percentage obtained

● Change the name of the Student from “Komal” to “Kunal”

Ans :RecordList[0]

RecordList[2][0]

RecordList[-1]

RecordList[0]=”Kunal”

Predict the output based on the list, cod = [98, 45, 62, 14, 1007]

1. print(len(cod+cod))

2. print(cod[2:4] * 3)

3. print(‘14’ not in cod)

4. print(50-5 in cod)

5. print(cod[::-1]+cod[0:1])

Ans : a.10

b. [62, 14, 62, 14, 62, 14]


c. True

d. True

e. [1007, 14, 62, 45, 98, 98]

Write Python statements for performing the following on a dictionary,

“PTM”

. To check whether the value “s1” is existing as the dictionary’s keys

a. To remove the key ‘s3’ and its corresponding values from the dictionary

b. To find the number of elements in a dictionary

c. To change the value corresponding to “s5” to 99

d. To find the minimum value among the keys of the dictionary

Ans . ‘s1’ in PTM

a. PTM. clear()

b. len(PTM)

c. PTM[‘s5’]=99

d. min(PTM)

You might also like