Embercode
✕
Dicts and SetsQuick quiz

Patterns and custom keys

8 questions. Covers Custom keys: __eq__, __hash__ and pair keys in Python.

Questions 1 to 5 of 8

  1. 1. A one-dict check that only goes from each letter of badc to the letter in the same position of baba returns True. Why is that wrong?
  2. 2. What does ''.split(' ') return in Python?
  3. 3. A student wrote this class and then tried to add a Point to a set. What is the bug? ``python class Point: def __init__(self, x, y): self.x = x self.y = y def __eq__(self, other): return isinstance(other, Point) and self.x == other.x and self.y == other.y points = set() points.add(Point(3, 4)) ``
  4. 4. The check below returns False for the pattern abba and the sentence dog cat cat dog, which is wrong. What is the bug? ``python mapped = letter_to_word.get(letter) if mapped is None: letter_to_word[letter] = word elif mapped is not word: return False ``
  5. 5. A student says the strings 'ab' and 'aa' are isomorphic, which means each letter maps to one letter and no two letters share a partner. Is that true?

5 question(s) left on this page.