Created
September 20, 2014 12:38
-
-
Save stleon/6c567904f36de8720814 to your computer and use it in GitHub Desktop.
Строку из чисел в список на Python
This file contains 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 fib(n): | |
x, y = 0, 1 | |
while n: | |
yield x | |
x, y = y, x + y | |
n -= 1 | |
def fib_string(): | |
fib_str = '' | |
for i in fib(1000): | |
fib_str = '%s %s' % (fib_str, str(i)) if fib_str else str(i) | |
return fib_str | |
def mk(fib_str): | |
return map(int, fib_str.split()) | |
def fk(fib_str): | |
return (int(i) for i in fib_str.split()) | |
def gk(fib_str): | |
return [int(i) for i in fib_str.split()] | |
def inum(fib_str): | |
num = '' | |
for index, i in enumerate(fib_str): | |
num = num + i | |
if i == ' ' or index == len(fib_str)-1: | |
yield int(num) | |
num = '' | |
if __name__ == '__main__': | |
fib_str = fib_string() | |
#mk(fib_str) | |
#fk(fib_str) | |
#inum(fib_str) | |
mk_list = list(mk(fib_str)) | |
fk_list = list(fk(fib_str)) | |
gk_list = gk(fib_str) | |
inum_list = list(inum(fib_str)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment