Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
actor = {"name": "John Cleese", "rank": "awesome"}

def get_last_name():
    return actor["name"].split()[1]

get_last_name()
print("All exceptions caught! Good job!")
print("The actor's last name is %s" % get_last_name())


Accessing dictionary values

Code Block
x = [
	'a',
	'b',
	{
		'foo': 1,
		'bar':
		{
			'x' : 10,
			'y' : 20,
			'z' : 30
		},
		'baz': 3
	},
	'c',
	'd'
]

print(x[2]['bar']['z'])

Result

Code Block
30


Delete dictionary element

Deleting a element by statement

Code Block
del d['foo']

Deleting a element by method

Code Block
d.pop('foo')


Generator

Random number generation

...