1. Write a Python program to convert a tuple to a string.
2. Write a Python program to get the 4th element from the last element of a tuple.
3. Write a Python program to find repeated items in a tuple.
4. Write a Python program to check whether an element exists within a tuple.
5. Write a Python program to find the length of a tuple.
6. Write a Python program to convert a tuple to a dictionary.
7. Write a Python program to print a tuple with string formatting.
Sample tuple : (100, 200, 300)
Output : This is a tuple (100, 200, 300)
8. Write a Python program to sort a tuple by its float element.
Sample data: [('item1', '12.20'), ('item2', '15.10'), ('item3', '24.5')]
Expected Output: [('item3', '24.5'), ('item2', '15.10'), ('item1', '12.20')]
9. Write a Python program to calculate the product, multiplying all the numbers in a given
tuple.
Original Tuple:
(4, 3, 2, 2, -1, 18)
Product - multiplying all the numbers of the said tuple: -864
Original Tuple:
(2, 4, 8, 8, 3, 2, 9)
Product - multiplying all the numbers of the said tuple: 27648
10. Write a Python program to convert a given tuple of positive integers into an integer.
Original tuple:
(1, 2, 3)
Convert the said tuple of positive integers into an integer:
123
Original tuple:
(10, 20, 40, 5, 70)
Convert the said tuple of positive integers into an integer:
102040570
11. Write a Python script to sort (ascending and descending) a dictionary by value.
12. Write a Python script to generate and print a dictionary that contains a number (between 1
and n) in the form (x, x*x).
Sample Dictionary ( n = 5) :
Expected Output : {1: 1, 2: 4, 3: 9, 4: 16, 5: 25}
13. Write a Python script to merge two Python dictionaries.
14. Write a Python program to combine two dictionary by adding values for common keys.
d1 = {'a': 100, 'b': 200, 'c':300}
d2 = {'a': 300, 'b': 200, 'd':400}
Sample output: Counter({'a': 400, 'b': 400, 'd': 400, 'c': 300})
15. Write a Python program to create and display all combinations of letters, selecting each
letter from a different key in a dictionary.
Sample data : {'1':['a','b'], '2':['c','d']}
Expected Output:
ac
ad
bc
bd