What will be the output of the following Python code?
numberGames = {}
numberGames[(1,2,4)] = 8
numberGames[(4,2,1)] = 10
numberGames[(1,2)] = 12
sum = 0
for k in numberGames:
sum += numberGames[k]
print len(numberGames) + sum
a) 30
b) 24
c) 33
d) 12
Answer: c
Explanation: Tuples can be used for keys into dictionary. The tuples can have mixed length and the order of the items in the tuple is considered when comparing the equality of the keys.
Related Posts
What is the observation made in the following JavaScript code?
var count = [1,,3];What will be the output of the following JavaScript code?
const obj = {prop: 12};
Object.preventExtensions(obj);
console.log( Object.isExtensible(obj));What will be the output of the following JavaScript code?
const object1 = {
property1: 20
};
console.log(Object.is(object1));What will be the output of the following JavaScript code?
const obj1 = { property1: ’10’};
const obj2 = Object.freeze(obj1);
obj2.property1 = ’20’;
console.log(obj2.property1);What will be the output of the following JavaScript code?
const obj1 =
{
property1: 21
}
const descriptor1 = Object.getOwnPropertyDescriptor(obj1, ‘property1’);
console.log(descriptor1.configurable);
console.log(descriptor1.enumerable);What will be the output of the following JavaScript code?
const object1 = {};
a = Symbol(‘a’);
b = Symbol.for(‘b’);
object1[a] = ‘harry’;
object1[b] = ‘derry’;
const objectSymbols = Object.getOwnPropertySymbols(object1);
console.log(objectSymbols.length);The basic purpose of the toLocaleString() is to _________
Join The Discussion