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
| another_list = [(i*7 + 5) % 13 if i%2==0 else (i*5 + 7) % 23 for i in range(k) ] |
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
| def new_function(i): | |
| if i%2==0: | |
| return (i*7 + 5) % 13 | |
| else: | |
| return (i*5 + 7) % 23 | |
| # It would probably be even better if | |
| # that number behavior was handled like this: | |
| def conversion(i, prod, add, mod): | |
| return (i*prod + add) % mod | |
| #final_version |
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
| another_list = [conversion(i) for i in range(k)] |
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
| id_matrix = [[1,0,0], | |
| [0,1,0], | |
| [0,0,1]] | |
| vector_version = [n for row in id_matrix for n in row] |
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
| some_list = [1,2,3,4,5,6,7,8,9] | |
| only_even = [n for n in some_list if n%2==0] | |
| def even(n): | |
| return n%2 == 0 | |
| only_even_prettier = [n for n in some_list if even(n) ] |
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
| def num_object(k): | |
| return {'number':k, 'double':2*k} | |
| many_instances = [num_object(k) for k in range(20)] |
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
| string_first_100 = [str(k) for k in range(100)] | |
| single_string = ', '.join( [str(k) for k in range(100)] ) |
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
| dict_of_doubles = { | |
| str(k) : 2*k for k in range(100) | |
| } | |
| dict_of_multiples_of_4 = { | |
| str(k) : 2*k for k in range(100) if k%2==0 | |
| } |
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
| import time | |
| BIG = 20000000 | |
| def f(k): | |
| return 2*k | |
| def list_a(): | |
| list_a = [] | |
| for i in range(BIG): |
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_comprehension = [f(i) for i in range(10)] # for some function f... | |
| list_generator = (f(i) for i in range(10) ) # for some function f... |