easier to understand | Sololearn: Learn to code for FREE!

easier to understand

from itertools import product, permutations letters = ("A", "B","c") print(list(product(letters, range(3)))) print(list(permutations(letters))) Result: [('A', 0), ('A', 1), ('A', 2), ('B', 0), ('B', 1), ('B', 2), ('c', 0), ('c', 1), ('c', 2)] [('A', 'B', 'c'), ('A', 'c', 'B'), ('B', 'A', 'c'), ('B', 'c', 'A'), ('c', 'A', 'B'), ('c', 'B', 'A')]

13th Jul 2018, 3:53 AM
ahoo110 gao
ahoo110 gao - avatar
1 Respuesta
the first line using the product() function goes through each letter in letters and creates a tuple with each number in range 3 (so it would be 0 1 2). Then the whole thing is converted to a list and printed. The second line that uses permutations() i believe combines all the letters in different combinations to cover all possible combolinations aka permutations. All possible combinations would be how many letters there are (3) multiplied by each other letter (2 more) which equals 6 (same length as in tbe output above).
22nd Jul 2018, 12:00 PM
Dave David
Dave David - avatar