G
G
Gast0n2020-05-20 14:57:46
Python
Gast0n, 2020-05-20 14:57:46

How to generate options?

Hello. Tell the function how to generate all possible options and save them to a list.
For example:
name = 'sasha'
surname = 'petrov'
birth_date = '11/01/1985' # here it is also desirable to split by a dot nickname =
'sanek' sashasanek, etc. In general, to get all possible combinations of these values. There are 6 of them here.


Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladimir Kuts, 2020-05-20
@Gast0n

from itertools import permutations
name = 'sasha'
surname = 'petrov'
birth_date = '11.01.1985' # тут еще желательно разбить по точке
nickname = 'sanek'

for j in range(3):
    for im in permutations(birth_date.split('.'), j+1):
      for x in permutations([name, surname, nickname, ''.join(im)], 2):
          print(''.join(x))

sashapetrov
sashasanek
sasha19850111
petrovsasha
petrovsanek
petrov19850111
saneksasha
sanekpetrov
sanek19850111
19850111sasha
19850111petrov
19850111sanek
sashapetrov
sashasanek
sasha19850111
petrovsasha
petrovsanek
petrov19850111
saneksasha
sanekpetrov
sanek19850111
19850111sasha
19850111petrov
19850111sanek
sashapetrov
sashasanek
sasha19850111
petrovsasha
petrovsanek
petrov19850111
...
alone - many repetitions will

G
Gast0n, 2020-05-20
@Gast0n

Thank you. I have this code

import itertools

info = ['maria', 'ivanova', '12', '05', '1995', 'masha']

base = list(itertools.combinations_with_replacement(info, 3))

print(base)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question