How can I get “permutations with repetitions/replacement” from a list (Cartesian product of a list with itself)?

You are looking for the Cartesian Product. In mathematics, a Cartesian product (or product set) is the direct product of two sets. In your case, this would be {1, 2, 3, 4, 5, 6} x {1, 2, 3, 4, 5, 6}. itertools can help you there: import itertools x = [1, 2, 3, 4, 5, … Read more

Set partitions in Python

Since this nice question has been brought back to life, here’s a fresh answer. The problem is solved recursively: If you already have a partition of n-1 elements, how do you use it to partition n elements? Either place the n‘th element in one of the existing subsets, or add it as a new, singleton … Read more

How can I print out all possible letter combinations a given phone number can represent?

In Python, iterative: digit_map = { ‘2’: ‘abc’, ‘3’: ‘def’, ‘4’: ‘ghi’, ‘5’: ‘jkl’, ‘6’: ‘mno’, ‘7’: ‘pqrs’, ‘8’: ‘tuv’, ‘9’: ‘wxyz’, } def word_numbers(input): input = str(input) ret = [”] for char in input: letters = digit_map.get(char, ”) ret = [prefix+letter for prefix in ret for letter in letters] return ret ret is a … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)