This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
keycode = 2 | |
functions = {1: func1, 2: func2, 3: func3} | |
functions.get(keycode, default_func)() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# start_dict = {'Dick': '[email protected]', 'Jane': '[email protected]', 'Stou': '[email protected]'} | |
result_dict = dict( [name, '.com' in email] for name, email in start_dict.iteritems() ) | |
# result_dict = {'Dick': True, 'Jane': True, 'Stou': False} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
start_list = [1,2,3,3,4,1] | |
set(start_list) | |
# возвращает set([1,2,3,4]) | |
if len(start_list) == len(set(start_list)): | |
print 'List is unique!' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
letters = ['a', 'b', 'c'] | |
numbers = [1, 2, 3] | |
squares = [1, 4, 9] | |
zipped_list = zip(letters, numbers, squares) | |
# zipped_list = [('a', 1, 1), ('b', 2, 4), ('c', 3, 9)] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# start_list = [1,10,100,1000,10000] | |
if all(item < 10 for item in start_list): | |
print 'Success' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# start_list = [1,10,100,1000,10000] | |
if any(item < 10 for item in start_list): | |
print 'Success' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# list = ['a', 'b', 'c', 'd', 'e'] | |
for index, item in enumerate(list): | |
print index, item | |
# печатает "0 a 1 b 2 c 3 d 4 e" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# start_list = [1,2,3,4,5] | |
result = reduce(lambda a,b: a+b, start_list) | |
# result = 120 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
flatten_list = [item for sublist in start_list for item in sublist] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[user] | |
name = wowkalucky | |
email = [email protected] | |
[core] | |
whitespace = fix,-indent-with-non-tab,trailing-space,cr-at-eol | |
excludesfile = ~/.gitignore | |
editor = nano | |
[color] |