Python Forum
looking for code: combinations of letter in order
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
looking for code: combinations of letter in order
#6
(Nov-18-2017, 05:04 AM)heiner55 Wrote: If you stumble across an easy algorithmn without itertools,
let me know. Thanks.

i have not tested this idea, yet.  for a given sequence of n items, iterate over range(1,2**n) as b..  get a string of bits representing b and start an empty list.  iterate through this string of bits.  for each bit that is 1 get the corresponding element from the given sequence at the same position and append it to the list.  when the iteration of bits is done, yield the resulting list (or append it to the big list to be returned).

yes, i am thinking this should be a generator or a stack of generators.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Messages In This Thread
RE: looking for code: combinations of letter in order - by Skaperen - Nov-18-2017, 08:06 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020