Quiz Catalog

Catalog of quizzes

text = '1,2,3'
d = dict.fromkeys(text)

print(len(d))
4
  • dict/operation/fromkeys

x = ('key1', 'key2', 'key3')
y = 0

value = dict.fromkeys(x, y)

print(value) 
{'key1': 0, 'key2': 0, 'key3': 0}
  • dict/operation/fromkeys

class A:
  def __init__(self, i):
  self.i = i

x = [A(1), A(2), A(3)]
y = 0

value = dict.fromkeys(x, y)

print(value)
{<__main__.A object at ref>: 0, <__main__.A object at ref>: 0, <__main__.A object at ref>: 0}
  • dict/operation/fromkeys

x = [1, 2, 3]
y = [2, 3, 5]

value = dict.fromkeys(x, y)

print(value)
{1: [2, 3, 5], 2: [2, 3, 5], 3: [2, 3, 5]}
  • dict/operation/fromkeys

x = [ { "i": 1 }, { "i": 3 }, { "i": 2 } ]
y = 1

value = dict.fromkeys(x, y)

print(value)
TypeError: unhashable type: 'dict'
  • dict/operation/fromkeys

x = { 1, 2, 3 }

value = dict.fromkeys(x)

print(value)
{1: None, 2: None, 3: None}
  • dict/operation/fromkeys

elements = [1, 2, 3]
res_elements = dict.fromkeys(elements, elements ** 2)

print(res_elements)
TypeError: unsupported operand type(s) for ** or pow(): 'list' and 'int'
  • dict/operation/fromkeys