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

Using 'append' method on nested lists gives syntax error [closed]

$
0
0

given a set of letter combinations (aa,ab)and a set of numbers (1,2,3)

I want to generate:

(aa1,ab2) (aa1,ab3)(aa2,ab1) (aa2,ab3)(aa3,ab1) (aa3,ab2)

This is the pairing algorithm I have written and it seems to work.

numlist =(1,2,3,4)letter_combinations=("pa","pb","pc")i=0for num1 in numlist:    for num2 in numlist:        if num1 != num2:            used_combinations = set()            for comb1 in letter_combinations:                for comb2 in letter_combinations:                    if comb1 != comb2 and comb2 not in used_combinations:                        print(f"({comb1}{num1},{comb2}{num2})", end=" ")                        i += 1                        used_combinations.add(comb1)            print()print(i)

is there a more 'pythonic' way to do this?


Viewing all articles
Browse latest Browse all 18819

Trending Articles



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