1)Program to check if the Given List is in Ascending Order or Not
Code: |
---|
|
2)Program to Find Even Numbers From a List
Code: |
---|
|
3)Program to Merge Two Lists
Code: |
---|
|
4)Interchange First and Last Element of a List
Code: |
---|
|
5)Program to Subtract a List from Another List
Code: |
---|
|
6)Program to Get Data Items From a List Appearing Odd Number of Times
Code: |
---|
|
7) Add a new pair of key (e.g. c ) and value (e.g. 3 ) to the dictionary and print out the new dictionary.
d = {"a": 1, "b": 2}
Code:
d = {"a": 1, "b": 2}
print("Old Dictionary: ",d)
d["c"]=3
print("New Dictionary: ",d)
Output:
Old Dictionary: {'a': 1, 'b': 2}
New Dictionary: {'a': 1, 'b': 2, 'c': 3}
8) Complete the script so that it prints out the letter i using negative indexing.
letters = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]
Code:
letters = ["a", "b", "c", "d", "e", "f", "g", "h", "i","j"]
a = letters[-2]
print("Letter :",a)
Output:
Letter : i
9) Complete the script so that it removes duplicate items from the list a.
a = ["1", 1, "1", 2]
Code:
a = ["1", 1, "1", 2]
a = list(set(a))
print("Updated List:",a)
Output:
Updated List: [1, 2, '1']