Assignment 2 Questions LIST Tuples Dict

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

Assignment 2

Questions on Lists
1. Explain List data type, with an example program to illustrate the same.
2. Explain how to get individual values from a list with an example program to illustrate the same.
3. Explain Index Error and Type Error with an example program for each.
4. Explain the concept of “list within a list” with an example program, also explain how to access
the items from a “list within a list”.
5. Explain the concept of Getting a list from another list with an example program for the same.
6. Explain with an example program to change the items in a list and delete a item from a list.
7. Explain the concept of list concatenation and list replication with an example program.
8. Write a python program to fetch 5 friends name and store it in a list. And display the list which
consists of 5 friends.
9. Explain the concept of iterating the list with an example program.
10. Explain “in” and “not in” operator in the list with an example program.
11. Explain the concept of enumerate () function in list with an example program.
12. Explain random.choice() and random.shuffle() functions in list with an example program for
each.
13. List out and explain augmented assignment operators with an example for each.
14. Explain the following list methods with an examples:
a) index()
b) append()
c) insert()
d) remove()
e) sort()
f) sorting a list in descending order
g) reverse()
h) list()
15. Explain why Lists are mutable with examples to illustrate the same.
16. Explain the difference between reverse() and sort(reverse = True) with an example program.
17. Write a python program to add ‘n’ names into a list and display random name as a output.
18. Write a python program to count even and odd numbers in a list.
19. Write a python program to perform sum of even numbers and product of odd numbers in a list.
20. Make a list of first ten letters of the alphabet then using the slice operation do the following: 1)
print the first three letters from the list 2) print any three letters from the middle 3) print the
letters from 5th letters to the end of the list.
21. What is the difference between the append() and insert() list methods?
22. For the following three questions, lets say bacon contains the list [3.14, ‘cat’, 11, ‘cat’, True]
a) what does bacon.index('cat') evaluate to?
b) what does bacon.append(99) make the list value in bacon look like?
c) what does bacon.remove('cat') make the list value in bacon look like?
23. For the following three questions, lets say spam contains the list ['a','b','c','d']
a) what does spam[-1] evaluate to?
b) what does spam[:2] evaluate to?
Questions on Tuples
1. Explain tuple data type with an example program.
2. Explain list() and tuple() with an example program.
3. Explain List, tuple within a tuple with an example program.
4. Explain identity and id() function with an example program.
5. Explain the concept of passing references with an example program.
6. Explain the concept of iterating though a tuple with an example program.
7. Explain the concept of indexing and slicing in tuples.
8. Explain below methods in a tuple with an example program for each.
a)count()
b)index()
c)max()
d)min()
9. What are the differences between list and tuple?
Questions on Dictionary
1. Explain dictionary creation with syntax and an example program.
2. Explain add and change of elements in a dictionary with an example programs.
3. Explain how to access the value from a dictionary with an example program.
4. Explain Dictionaries vs List with respect to sequences. Explain the same with an example
program.
5. Explain how to remove elements from a dictionary with an example program.
6. Explain below methods in dictionary with an example program for each
a) clear()
b) copy()
c) fromkeys()
d) get()
e) items()
f) keys()
g) values()
h) popitems()
i) pop()
j) update()
k) setdefault()
7. Explain the concept of Pretty Printing with an example program.
8. Explain the concept of Nested Dictionary. Explain how to access the dictionary, add elements
into a dictionary, add a key into a dictionary, delete the item with an example program for
each.
9. Explain the concept of checking whether the key or value exists in dictionary or not with the
help of an example program.
10. List out the differences between strings, lists, tuple, dictionary with example program for each.

You might also like