Python find all possible combinations of letters
I am generating all possible three letters keywords Show
Can this functionality be achieved in a more sleek and efficient way?
agf 164k40 gold badges278 silver badges232 bronze badges asked Aug 16, 2011 at 5:46
Aamir RindAamir Rind 37.5k21 gold badges121 silver badges158 bronze badges
See the
documentation for
will work if you just want the lowercase ascii letters. answered Aug 16, 2011 at 5:48
2 You could also use map instead of the list comprehension (this is one of the cases where map is still faster than the LC)
This variation of the list comprehension is also faster than using
answered Aug 16, 2011 at 6:08
John La RooyJohn La Rooy 286k51 gold badges358 silver badges498 bronze badges 2
agf 164k40 gold badges278 silver badges232 bronze badges answered Aug 16, 2011 at 6:54
AsteriskAsterisk 3,5062 gold badges34 silver badges53 bronze badges 1 You can also do this without any external modules by doing simple calculation.
Give it an iterable object and an integer as the output-length.
This will start from 'aaa' and end with 'zzz'.
agf 164k40 gold badges278 silver badges232 bronze badges answered Aug 19, 2011 at 9:15
Niklas RNiklas R 15.6k25 gold badges94 silver badges197 bronze badges
answered Aug 16, 2011 at 7:32
We could solve this without the itertools by utilizing two function definitions:
It's done using two functions to avoid resetting the length of the alphas, and the second function self-iterates itself until it reaches a k of 0 to return the k-mer for that i loop. Adopted from a solution by Abhinav Ramana on Geeks4Geeks answered Feb 28, 2019 at 6:21
1 Well, i came up with that solution while thinking about how to cover that topic:
Please let me describe what is going on inside:
answered Jan 5 at 11:42
2
This removes the repetition of characters in one string
a_r 4606 silver badges12 bronze badges answered Jan 21, 2017 at 0:58
How do you get all the possible combinations of letters in Python?Practical Data Science using Python. st_arr := a new list.. for i in range size of s - 1 to 0, decrease by 1, do. for j in range 0 to size of st_arr - 1, do. insert (s[i] concatenate st_arr[j]) at the end of st_arr. insert s[i] at the end of st_arr.. return st_arr.. How can I create all possible combination of words from characters of given word in Python?How can I create all possible combination of words from characters of given word in Python?. Code s='ABC' print list(itertools.permutations(s,2)). Output [('A','B'),('B','A'),('B','C'),('C','B'),('A','C'),('C','A')] ... . Code s='ABC' print list(itertools.combinations(s,2)). Output [('A','B'),('B','C'),('A','C')]. How many combinations of letters are possible?This gives that the number of combinations that are possible with the alphabet, or 26 letters, without repetition is 67,108,863.
How many combinations of three letters in a 26 letter alphabet are there?26⋅25⋅24=15600.
|