Python Forum
permutations of varying length
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
permutations of varying length
#2
These kinds of permutations are called «Arrangements» in classical mathematical literature (although there may be more modern terms to refer to them) See the paragraph about k-permutations of n here https://en.wikipedia.org/wiki/Permutatio...tions_of_n (note that these are only the 'restricted partial premutations' in https://en.wikipedia.org/wiki/Partial_pe...rmutations)

The following piece of code should do the trick
s = "abcde"                               
n = len(s)                                 
seq = (a for i in range(1, n+1) for c in itt.combinations(s, i) for a in itt.permutations(c, i))                                       
                                           
for x in seq:                             
    print(x)
Reply


Messages In This Thread
permutations of varying length - by Skaperen - Feb-15-2022, 01:22 AM
RE: permutations of varying length - by Gribouillis - Feb-17-2022, 10:43 PM
RE: permutations of varying length - by Skaperen - Feb-18-2022, 12:02 AM
RE: permutations of varying length - by Gribouillis - Feb-18-2022, 06:58 AM
RE: permutations of varying length - by Skaperen - Feb-19-2022, 10:41 AM

Forum Jump:

User Panel Messages

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