1: wl = ['a','b', 'c', 'd', 'e', 'f', '']But I think everyone can see that that was a stupid idea.
2: out = []
3:
4: for i1 in set(wl):
5: for i2 in set(wl):
6: for i3 in set(wl):
7: for i4 in set(wl):
8: for i5 in set(wl):
9: for i6 in set(wl):
10: for i7 in set(wl):
11: types = i1+i2+i3+i4+i5+i6+i7
12: out.append(types)
Saying that I have seen that in quite some projects. My next thought was to bring recursion into this.
1: wl = ['a','b', 'c', 'd', 'e', 'f', ' ']
2: out = []
3:
4: def recLoop(txt):
5: if len(txt) >= len(wl):
6: out.append(txt.replace(' ',''))
7: else:
8: for i in set(wl):
9: recLoop(txt + i)
This looks far nicer doesn't it. I hope everyone who programs can see this. Just to state how important recursion is and I don't really understand why unis don't teach this more.
No comments:
Post a Comment