all possible combinations

Paul Rubin http
Thu Jul 14 15:57:08 EDT 2005


rbt <rbt at athop1.ath.vt.edu> writes:
> Say I have a list that has 3 letters in it:
> 
> ['a', 'b', 'c']
> 
> I want to print all the possible 4 digit combinations of those 3
> letters:

for i in xrange(81):
  print ''.join(['abcd'[j]  
                 for j in [(i//d)%3 for d in (27,9,3,1)]])



More information about the Python-list mailing list