[Tutor] lambdas, generators, and the like

Keith Winston keithwins at gmail.com
Sun Jan 12 10:04:48 CET 2014


I've got this line:

for k in range(len(tcombo)):
    tcombo_ep.append(list(combinations(tcombo, k+1)))

generating every possible length combination of tcombo. I then test
them, and throw most of them away. I need to do this differently, it
gets way too big (crashes my computer).

I'm going to play some more, but I think I need to test the
combinations as they're generated... and then only add them to a list
(probably better: a set) if they meet a requirement (something like
sum(specific.combination(tcombo) == goal)) AND if they are not already
part of that list (the uniqueness issue is why a set might be better)

I'm partially asking in order to clarify the question in my mind, but
any help will be appreciated. I don't really understand lambda
functions yet, but I can sort of imagine they might work here
somehow... or not.

Thanks!

-- 
Keith


More information about the Tutor mailing list