-
Notifications
You must be signed in to change notification settings - Fork 0
Completed about_dictionaries koan #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,47 +13,47 @@ def test_creating_dictionaries(self): | |
| empty_dict = dict() | ||
| self.assertEqual(dict, type(empty_dict)) | ||
| self.assertEqual(dict(), empty_dict) | ||
| self.assertEqual(__, len(empty_dict)) | ||
| self.assertEqual(0, len(empty_dict)) | ||
|
|
||
| def test_dictionary_literals(self): | ||
| empty_dict = {} | ||
| self.assertEqual(dict, type(empty_dict)) | ||
| babel_fish = {'one': 'uno', 'two': 'dos'} | ||
| self.assertEqual(__, len(babel_fish)) | ||
| self.assertEqual(2, len(babel_fish)) | ||
|
|
||
| def test_accessing_dictionaries(self): | ||
| babel_fish = {'one': 'uno', 'two': 'dos'} | ||
| self.assertEqual(__, babel_fish['one']) | ||
| self.assertEqual(__, babel_fish['two']) | ||
| self.assertEqual('uno', babel_fish['one']) | ||
| self.assertEqual('dos', babel_fish['two']) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Q2: Can
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also can.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. May sound like an Idle question, but |
||
|
|
||
| def test_changing_dictionaries(self): | ||
| babel_fish = {'one': 'uno', 'two': 'dos'} | ||
| babel_fish['one'] = 'eins' | ||
|
|
||
| expected = {'two': 'dos', 'one': __} | ||
| expected = {'two': 'dos', 'one': "eins"} | ||
| self.assertEqual(expected, babel_fish) | ||
|
|
||
| def test_dictionary_is_unordered(self): | ||
| dict1 = {'one': 'uno', 'two': 'dos'} | ||
| dict2 = {'two': 'dos', 'one': 'uno'} | ||
|
|
||
| self.assertEqual(____, dict1 == dict2) | ||
| self.assertEqual(True, dict1 == dict2) | ||
|
|
||
| def test_dictionary_keys_and_values(self): | ||
| babel_fish = {'one': 'uno', 'two': 'dos'} | ||
| self.assertEqual(__, len(babel_fish.keys())) | ||
| self.assertEqual(__, len(babel_fish.values())) | ||
| self.assertEqual(__, 'one' in babel_fish.keys()) | ||
| self.assertEqual(__, 'two' in babel_fish.values()) | ||
| self.assertEqual(__, 'uno' in babel_fish.keys()) | ||
| self.assertEqual(__, 'dos' in babel_fish.values()) | ||
| self.assertEqual(2, len(babel_fish.keys())) | ||
| self.assertEqual(2, len(babel_fish.values())) | ||
| self.assertEqual(True, 'one' in babel_fish.keys()) | ||
| self.assertEqual(False, 'two' in babel_fish.values()) | ||
| self.assertEqual(False, 'uno' in babel_fish.keys()) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Q: What type are the return values of
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It returns |
||
| self.assertEqual(True, 'dos' in babel_fish.values()) | ||
|
|
||
| def test_making_a_dictionary_from_a_sequence_of_keys(self): | ||
| cards = {}.fromkeys( | ||
| ('red warrior', 'green elf', 'blue valkyrie', 'yellow dwarf', | ||
| 'confused looking zebra'), | ||
| 42) | ||
|
|
||
| self.assertEqual(__, len(cards)) | ||
| self.assertEqual(__, cards['green elf']) | ||
| self.assertEqual(__, cards['yellow dwarf']) | ||
| self.assertEqual(5, len(cards)) | ||
| self.assertEqual(42, cards['green elf']) | ||
| self.assertEqual(42, cards['yellow dwarf']) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: line break before end of file. |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Q1: Can
Nonebe a valid key?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it can.