On 2021-01-08, Stefan Ram wrote:
> Bischoop writes:
>>What I want to learn is if I need get for example four combinations, so
>>how to get in a loop first letter 'a',then another step'a' and again 'a'
>>and 'a', to have '' later on'abaa' etc.
>
> I can only guess what you want, maybe
Is this "code golf"? Can anybody play? Here's another approach:
Define a function like this:
def embiggen(wordlist):
alpha = 'abc'
return [x for x in alpha] + [x+y for x in alpha for y in wordlist]
It makes every word in its input one letter longer in each possible
way, and returns all of
On Fri, Jan 8, 2021 at 11:31 AM Greg Ewing wrote:
>
> Another way to approach this problem is using recursion, e.g.
>
> def find_combinations(items, n, comb, result):
>if n == 0:
> result.append(comb)
>else:
> for item in items:
>find_combinations(items, n - 1, comb +
Another way to approach this problem is using recursion, e.g.
def find_combinations(items, n, comb, result):
if n == 0:
result.append(comb)
else:
for item in items:
find_combinations(items, n - 1, comb + [item], result)
words = []
find_combinations(['a', 'b', 'c'], 3, [],
On 08/01/2021 05.52, Bischoop wrote:
> On 2021-01-07, Chris Angelico wrote:
>>
>> True. Unfortunately, it doesn't work, so what you'd have is something
>> that can be easily parameterized to not work on other numbers of
>> characters too. :)
>>
>
> My bad is I'm kinda maniac and have to know how
I find a parallel to counting useful. Let letters be '0' to '9'
and think of manual (in contrast to formatting range(0, 10))
construction of list of strings "" to ""
Let's start with . How do you compute the next item? Start
looking from its end. I stop here in order to leave space
On 2021-01-07, Bischoop wrote:
> On 2021-01-07, Chris Angelico wrote:
>>
>> True. Unfortunately, it doesn't work, so what you'd have is something
>> that can be easily parameterized to not work on other numbers of
>> characters too. :)
>>
>
> My bad is I'm kinda maniac and have to know how to, I
On 2021-01-07, David Raymond wrote:
> I think you might want to check out itertools.product()
> https://docs.python.org/3.9/library/itertools.html#itertools.product
Thanks David for contribution I find it very convenient but not knowing
how to solve solution without itertools for:
for a i :
On 2021-01-07, Chris Angelico wrote:
>
> True. Unfortunately, it doesn't work, so what you'd have is something
> that can be easily parameterized to not work on other numbers of
> characters too. :)
>
My bad is I'm kinda maniac and have to know how to, I know best solution
itertool but... I just
On Fri, Jan 8, 2021 at 2:12 AM Bischoop wrote:
>
> On 2021-01-07, Chris Angelico wrote:
>
> This could allow easy to change the number of characters in
> combination, just pass n argument to range where n is how many characters.
>
True. Unfortunately, it doesn't work, so what you'd have is
I think you might want to check out itertools.product()
https://docs.python.org/3.9/library/itertools.html#itertools.product
import itertools
import string
passe = 'pass'
for p in itertools.product(string.ascii_lowercase, repeat = 4):
p = "".join(p)
if p == passe:
print("Found
On 2021-01-07, Chris Angelico wrote:
This could allow easy to change the number of characters in
combination, just pass n argument to range where n is how many characters.
--
https://mail.python.org/mailman/listinfo/python-list
On 2021-01-07, Chris Angelico wrote:
>
> I'd recommend having just a string, rather than a list; it'll behave
> identically for what you're doing, and it'll be a lot easier to see
> when you have all the right letters.
>
Yes that's definitely better, I've done so.
>> mineset= set()
>> for a in
On Thu, Jan 7, 2021 at 8:46 PM Bischoop wrote:
> What I want to learn is if I need get for example four combinations, so
> how to get in a loop first letter 'a',then another step'a' and again 'a'
> and 'a', to have '' later on'abaa' etc.
So you want every possible four-letter combination?
>
14 matches
Mail list logo