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

Assignment 1

Uploaded by

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

Assignment 1

Uploaded by

piyushshah16op
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

ASSIGNMENT 2

Q1. What will be the output of following code:


(1) L=[3, 5, 1, 10, 2]
L.append(55)
print(L)

(2) X = [5, 10, ‘python’, ‘XI’, 5.6,90]


a. X[X[0]]
b. X[-1 : -5]
c. X.insert(3, 99)

(3) list1 = [1,2,3,4,5,6,7,8,9,10]


list1[::-2] list1[:3] + list1[3:]

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


list1[len(list1)-1]

Q 2 Write a command to delete key_value pair for key=”tiger ” in dictionary?

dic={"lion":"wild","tiger":"wild","cat":"domestic","dog":"domestic"}

Q 3 Find the output of following :


(i) print (tup [:-1 ] )
(ii) print (tup [0 : 4] )
(iii) print(tup[0:5])
(iv) print (tup[-5:])
If tup= (3,5,1,6,7,0)

Q 4 Write a function LShift(Arr,n) in Python, which accepts a list Arr of numbers and n is a numeric value
by which all elements of the list are shifted to left. Sample Input Data of the list Arr= [10,20,30,40,12,11],
n=2
Output Arr = [30,40,12,11,10,20]

Q 5. Predict the output:


D={'U1':'Programming', 'U2':'Data structures','U3':'Files', 'U4':'RDBMS', 'U5':'Networks'}
print(D.pop('U1'))
print(D.popitem())

Q 6. Take a list l1 of 10 elements. Store even and odd number in two different list from list l1.

Q 7. What will be the output of following program: list("a#b#c#d".split('#'))


Q 8. Concatenate following dictionaries to create a new one dic1={1:10, 2:20} dic2={3:30, 4:40} Expected
Result : {1: 10, 2: 20, 3: 30, 4: 40}

Q9. Write a program to input your friends name and their phone numbers, and store them as key value pair
in Dictionary Perform the following operations
a) Display name and phone number of all your friends
b) Search for a friends’ name in your list, if found display their phone number
c) Delete a particular friend
d) Modify the phone number of an existing friend
Page 1 of 2
Q 10 a. Differentiate between clear(), pop() and popitem() functions in Dictionary by giving example for
each.
b. Write the output of following Python code:
dict = {1: 4, 2: 5, 3: 1}
a=0
b=0
for i in dict.keys():
a=a+i
print(a)
for i in dict.values():
b=b+i
print(b)

Q 11(i)Write the output of the following Python code


t = (1,2,3,4,5,3,2,3,4,5,2,1)
print(t.count(2))
print(t.index(2))
(ii)Explain fromkeys(), setdefault() and copy() functions in Dictionary by giving example for each.

Q 12. Write the output of the following:


L=[10, 20, 30]
item = L.pop(1)
print('ITEM:',item)
list1=[3,2,1,0,1,2,3]
list1.remove(3)
print('SUM OF LIST:',sum(list1))
list1.insert(6,4)
print('UPDATED LIST1:',list1)
newList=L[:3]+list1[3:]
print('NEW LIST:',newList)

Page 2 of 2

You might also like