-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGenerators.py
More file actions
84 lines (69 loc) · 1.58 KB
/
Copy pathGenerators.py
File metadata and controls
84 lines (69 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# import matplotlib
# matplotlib.use('tkAgg') # bring upfront # TO AVOID: RuntimeError: Python is not installed as a framework.
import time
# from pylab import linspace
from numpy import sin, cos, pi
def city_generator():
yield("Konstanz")
yield("Zurich")
yield("Schaffhausen")
yield("Stuttgart")
city = city_generator()
try:
while True:
print(next(city))
except:
print("\nDone generating cities!")
def genum(n):
for i in range(n):
yield i
print(list(genum(37)))
def fibonacci(n):
"""Fibonacci numbers generator, first n"""
a, b, counter = 0, 1, 0
while True:
if (counter > n):
return
yield a
a, b = b, a + b
counter += 1
f = fibonacci(7)
for x in f:
print(x)
# print
def permutations(items):
n = len(items)
if n == 0:
yield []
else:
for i in range(len(items)):
for cc in permutations(items[:i] + items[i + 1:]):
yield [items[i]] + cc
for p in permutations(['r', 'e', 'd']):
time.sleep(0.0)
print(''.join(p))
for p in permutations(list("game")):
time.sleep(0.0)
print(''.join(p))
def stepcalc(x, y ,z):
yield x
inp = 0
while inp == 0:
yield y
inp = int(input("0/1?"))
yield z
step = stepcalc(0, 1, 2) # make it an object first!
a = next(step)
print("a:", a)
print("a:", a)
print(next(step))
print(next(step))
print(next(step))
print(next(step))
step = stepcalc(10, 20 ,30) # RESET
print(next(step))
print(next(step))
print(next(step))
print(next(step))
print(next(step))
print(next(step))