some functions about dictionary
dictionary.items()
dictionary.keys()
dictionary.values()
- dictionary = {“hello”:0, “world”:1}
- dictionary.items()
- [(‘world’, 1), (‘hello’, 0)]
- dictionary.keys()
- [‘world’, ‘hello’]
- dictionary.values()
- [1, 0]
list comprehension and list slicing
list = [i for i in range(1, 11) if i % 2 == 0]
list_slice = [1:11:1] #[index1:index2:stride length]
list_reverse = [::-1]
lambdas
One of the more powerful aspects of Python is that it allows for a style of programming called functional programming, which means that you’re allowed to pass functions around just as if they were variables or values. Sometimes we take this for granted, but not all languages allow this!
anonymous function.
filter()
print filter(lambda x: x % 2 != 0, range(1, 11))