Tuples and Dictionaries
Class 11 · Computer Science · 14 Questions
Consider the following tuples, tuple1 and tuple2: tuple1 = (23,1,45,67,45,9,55,45) tuple2 = (100,200) Find the output of the following statements:
Consider the following dictionary stateCapital: stateCapital = {"AndhraPradesh": "Hyderabad", "Bihar": "Patna", "Maharashtra": "Mumbai", "Rajasthan": "Jaipur"} Find the output of the following statements:
"Lists and Tuples are ordered". Explain.
With the help of an example show how can you return more than one value from a function.
What advantages do tuples have over lists?
When to use tuple or dictionary in Python. Give some examples of programming situations mentioning their usefulness.
Prove with the help of an example that the variable is rebuilt in case of immutable data types.
TypeError occurs while statement 2 is running. Give reason. How can it be corrected? >>> tuple1 = (5) #statement 1 >>> len(tuple1) #statement 2
Write a program to read email IDs of n number of students and store them in a tuple. Create two new tuples, one to store only the usernames from the email IDs and second to store domain names from the email IDs. Print all three tuples at the end of the program. [Hint: You may use the function split()]
Write a program to input names of n students and store them in a tuple. Also, input a name from the user and find if this student is present in the tuple or not. We can accomplish these by: (a) writing a user defined function (b) using the built-in function
Write a Python program to find the highest 2 values in a dictionary.
Write a Python program to create a dictionary from a string. Note: Track the count of the letters from the string. Sample string: 'w3resource' Expected output: {'3': 1, 's': 1, 'r': 2, 'u': 1, 'w': 1, 'c': 1, 'e': 2, 'o': 1}
Write a program to input your friends' names and their Phone Numbers and store them in the dictionary as the key-value pair. Perform the following operations on the dictionary:
For the SMIS System given in Chapter 5, let us do the following: Write a program to take in the roll number, name and percentage of marks for n students of Class X. Write user defined functions to - accept details of the n students (n is the number of students) - search details of a particular student on the basis of roll number and display result - display the result of all the students - find the topper amongst them - find the subject toppers amongst them [Hint: use Dictionary, where the key can be roll number and the value is an immutable data type containing name and percentage]