Worksheets › Class 11 › Working with Lists and Dictionaries › Cheat sheet

Class 11 Working with Lists and Dictionaries: cheat sheet

CBSE Informatics Practices. Lists: indexing, slicing, operators and methods; dictionaries: keys and values, adding, updating, deleting and traversing them.

Open the printable cheat sheetPractice worksheet

Key ideas

Remember

a = [10, 20, 30, 40, 50]a[1] → 20; a[-1] → 50; a[1:4] → [20, 30, 40]; a[::2] → [10, 30, 50]
+ and *; built-ins[1, 2] + [3] → [1, 2, 3]; [1, 2] * 2 → [1, 2, 1, 2]; for [4, 9, 2]: len 3, min 2, max 9, sum 15
pop and removepop() removes the LAST item and returns it; remove(x) removes the first x, by value
Third largesta.sort() then a[-3]; third smallest: a[2]
Dictionaryd = {'Asha': 78}; d['Asha'] = 81 updates; d['Ravi'] = 64 adds; del d['Ravi'] removes
len(d) after changesupdating a key: no change; a new key: one more; del: one fewer
Traversingfor k in d:     if d[k] >= 75:         print(k) # keys in the order added

Watch out

Worked example

Answer (a) to (c) for this program. a = [45, 47, 6, 37, 27] a.extend([63, 73]) a.insert(1, 6) p = a.pop() print(p) print(len(a)) print(a.index(6))

Working: after insert: [45, 6, 47, 6, 37, 27, 63, 73]; pop() removes the last item

Answer: (a) 73; (b) 7; (c) 1

Practise Working with Lists and Dictionaries

Revise with this page, then practise: every Working with Lists and Dictionaries sheet in the app is new, with an answer key and working.

Coming soon for Android and iPhone.