Python Dictionary and Tuple
Python Dictionary and Tuple
Python Dictionary and Tuple
company={1:"IBM",2:"Microsoft",3:"Apple",4:"Intel"}
del company[4]
i=0
i=i+1
print("Result :",i," : ",company)
company[4]="Intel"
company[5]="Dell"
l=len(company)
i=i+1 print("Result :",i," : ",l)
comp1=company.copy()
i=i+1 print("Result :",i," : ",company)
i=i+1 print("Result :",i," : ","1:",company.get(1))
i=i+1 print("Result :",i," : ",company.setdefault(3,"telnet"))
company.update(comp1)
i=i+1 print("Result :",i," : ",company)
keys = {'a', 'e', 'i', 'o', 'u' }
value = 'vowel'
vowels = dict.fromkeys(keys, value)
i=i+1 print("Result :",i," : ",vowels)
i=i+1 print("Result :",i," : ",company.keys())
i=i+1 print("Result :",i," : ",company.items())
i=i+1 element = company.pop(3)
print("Result :",i," : ",'The popped element is:', element)
result = company.popitem()
i=i+1 print("Result :",i," : ",'person = ',company)
i=i+1 print("Result :",i," : ",'Return Value = ',result)
i=i+1 print("Result :",i," : ",company.values())
i=i+1 print("Result :",i," : ",all(company))
i=i+1 print("Result :",i," : ",any(company))
i=i+1 print("Result :",i," : ",sorted(company))
people={1:{"name":"Shivam","age":19},2:{"name":"ashish","age":50}}
i=i+1 print("Result :",i," : ",people)
i=i+1 print("Result :",i," : ",people[1]["name"])
i=i+1 print("Result :",i," : ",people[2]["name"])
people[3]={"name":"priya","age":45}
i=i+1 print("Result :",i," : ",people)
del people[2]
i=i+1 print("Result :",i," : ",people)
a. WAP to input ‘N’ numbers of student’s name in a tuple and print the tuple in ascending
order of name?
b. Write a program that inputs two tuples seq_a and seq_b and prints True if every
element in seq_a is also an element of seq_b, else prints False.
c. Write a program that creates a tuple storing first 9 terms of Fibonacci Series.
d. Given a tuple pairs=((2,5),(4,2),(9,8),(12,10)), count the number of pairs(a,b) such that
both a and b are even.
e. Write a program as per the specification: Return the length of the shortest string in the
tuple of strings str_tuple. Precondition: the tuple will contain at least one element.
f. Write a Program to create a dictionary named year whose keys are month
names and values are their corresponding number of days.Write a Program that
repeatedly asks the user to enter product names and prices. Store all of them in a
dictionary whose keys are product names and values are prices. And also write a code
to search an item from the dictionary.
g. WAP to take the number of students as input then ask marks for five subjects. If the
total marks of any student are less than 200 the print ‘Fail’ or else print ‘Pass’. Use a
dictionary to store the student’s name as key and marks as values?
h. Write a Program that list the overlapping keys of the two dictionaries. list if the key of
D1 is the same as that of D2.
i. WAP to create a dictionary containing customer name with respective phone numbers,
search the name of the customer and print the phone number of that name.
j. There are 20 employees in a company write program to enter the PAN number, name
and annual salary and calculate the tax of all employees. The following table shows the
income tax slabs?
Annual income slab Tax rate
Income up to 2,50,000 No tax
Income from 2,50,000 to 5,00,000 5%
Income from 5,00,000 to 10,00,000 20%
Income more than 10,00,000 30%
Surcharge: 10% of income tax where total income exceed 50, 00,000 to
1, 00, 00,000 and 15% of income tax where total income exceeds 1, 00, 00,000.
Cess: 4% of total income tax