Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 13981

Python - Set first and last words of permutations

$
0
0

I'm looking to create a list of permutations but set the first and last words always the same.

import itertoolslist = ['cow', 'sheep', 'rooster', 'ram', 'donkey', 'horse', 'goat', 'pig']for x in range(1, len(list) + 1):    for i in itertools.permutations(list, x):        print ("".join(i))

So, for instance, how would I make the first word always be cow and the last word always be pig?


Viewing all articles
Browse latest Browse all 13981

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>