Question regarding problem #4 from assignment # 6, Word games 2: How can I iterate through a group of letters so that I find all possible arrangements of all lengths. In other words, all COMBINATIONS of letters from the original letters. If my letters were 'r c f t a b e', for example, I would want all possible 1 letter combinations, all possible 2 letter combinations, all possible 3 letter combinations, ..., all possible 7 letter combinations (which would be 1, since order does not matter). Any suggestions?
Do i really need as many for loops as there are letter in my original group of letters (seven in the example above)? Isn't there a way to automate it?
Look up itertools. It may come in handy to iterate over some combination of outcomes :-)
Thanks, found what i needed- is has a very useful combinations function I can use.
here is a combination generator (NOT permutations) http://pastebin.com/Lr26ZxZq
Thanks a lot guys. I used itertools.combinations and got it all worked out. Just wish I knew how people figured out some of these real complex lines of code (like the one for itertools.combinations-it's so clean).
Join our real-time social learning platform and learn together with your friends!