Computer Science
Predict the output
a = {(1,2):1,(2,3):2}	
print(a[1,2])
Python Dictionaries
5 Likes
Answer
Output
1
Explanation
a is a dictionary containing two key-value pair.(1,2) is a key of a. Therefore, a[1,2] represents value of key 1,2 i.e.,1
Answered By
3 Likes
Related Questions
- Predict the output: - fruit = {} L1 = ['Apple', 'banana', 'apple'] for index in L1 : if index in fruit: fruit[index] += 1 else : fruit[index] = 1 print(len(fruit)) print(fruit)
- Predict the output: - arr = {} arr[1] = 1 arr['1'] = 2 arr[1] += 1 sum = 0 for k in arr: sum += arr[k] print(sum)
- Predict the output - a = {'a':1, 'b':2, 'c':3} print(a['a','b'])
- Find the error/output. Consider below given two sets of codes. Which one will produce an error? Also, predict the output produced by the correct code. - (a) - box = {} jars = {'Jam' :4} crates = {} box['biscuit'] = 1 box['cake'] = 3 crates['box'] = box crates['jars'] = jars print(len(crates[box]))- (b) - box = {} jars = {'Jam' :4} crates = {} box['biscuit'] = 1 box['cake'] = 3 crates['box'] = box crates['jars'] = jars print(len(crates['box']))