Stuff1 | |||||||||
---|---|---|---|---|---|---|---|---|---|
The entire dictionary as coded | {'first':'Sam', 'last':'Sultan', 'gender':'M'} | ||||||||
The entire dictionary as per Python | {'first': 'Sam', 'last': 'Sultan', 'gender': 'M'} <-- Order is not guaranteed
The number of elements in dictionary | 3
| The content of element 'gender' | M
| stuff1 after change and insert | {'first': 'Samuel', 'last': 'Sultan', 'gender': 'M', 'id': '12345678', 'talent': 'none'}
| stuff1 after delete element 'talent' | {'first': 'Samuel', 'last': 'Sultan', 'gender': 'M', 'id': '12345678'}
| |
Stuff2 | |||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
The entire dictionary | {1: 'one', 2: 'two', 3: 'three', 4: 'four', 5: 'five', 6: 'six'} <-- Order is not guaranteed
The keys only | dict_keys([1, 2, 3, 4, 5, 6])
| The values only | dict_values(['one', 'two', 'three', 'four', 'five', 'six'])
| Sorting stuff2 by keys ascending | [1, 2, 3, 4, 5, 6]
| Sorting stuff2 by keys descending | [6, 5, 4, 3, 2, 1]
| Sorting stuff2 by values ascending | ['five', 'four', 'one', 'six', 'three', 'two']
| Sorting stuff2 by values descending | ['two', 'three', 'six', 'one', 'four', 'five']
| |
Stuff3 (a list containg dictionaries) | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
A list containg a dictionay | [{'id': 1, 'fname': 'Barbara', 'lname': 'Burns', 'ssn': '000-01-0001', 'sex': 'F'}, {'id': 2, 'fname': 'Vincent', 'lname': 'Cambria', 'ssn': '000-01-0002', 'sex': 'M'}, {'id': 3, 'fname': 'Duncan', 'lname': 'Davidson', 'ssn': '000-01-0003', 'sex': 'M'}]
Row 1 only | {'id': 1, 'fname': 'Barbara', 'lname': 'Burns', 'ssn': '000-01-0001', 'sex': 'F'}
| Row 2, last name | Cambria
| The length of stuff3 | 3
| The length of row 1 | 5
| Adding a new dictionary to the list | {'id': 4, 'fname': 'Sam', 'lname': 'Sultan', 'ssn': '000-01-0004', 'sex': 'M'}
| Sorting on first name ascending | [{'id': 1, 'fname': 'Barbara', 'lname': 'Burns', 'ssn': '000-01-0001', 'sex': 'F'}, {'id': 3, 'fname': 'Duncan', 'lname': 'Davidson', 'ssn': '000-01-0003', 'sex': 'M'}, {'id': 4, 'fname': 'Sam', 'lname': 'Sultan', 'ssn': '000-01-0004', 'sex': 'M'}, {'id': 2, 'fname': 'Vincent', 'lname': 'Cambria', 'ssn': '000-01-0002', 'sex': 'M'}]
| Sorting on first name descending | [{'id': 2, 'fname': 'Vincent', 'lname': 'Cambria', 'ssn': '000-01-0002', 'sex': 'M'}, {'id': 4, 'fname': 'Sam', 'lname': 'Sultan', 'ssn': '000-01-0004', 'sex': 'M'}, {'id': 3, 'fname': 'Duncan', 'lname': 'Davidson', 'ssn': '000-01-0003', 'sex': 'M'}, {'id': 1, 'fname': 'Barbara', 'lname': 'Burns', 'ssn': '000-01-0001', 'sex': 'F'}]
| |
Looping thru list of dictionaries | ||||
---|---|---|---|---|
id | fname | lname | ssn | sex |
1 | Barbara | Burns | 000-01-0001 | F |
2 | Vincent | Cambria | 000-01-0002 | M |
3 | Duncan | Davidson | 000-01-0003 | M |
4 | Sam | Sultan | 000-01-0004 | M |