Найти - Пользователи
Полная версия: Комбинация элементов в Python's style
Начало » Python для новичков » Комбинация элементов в Python's style
1
kampella
ch = ['a', 'b', 'c']
num = ['1', '2', '3']
Нужно получить все комбинации: a1,a2,a3,b1,b2,b3 и т.д.

Знаю можно пргнать через for:

all = []
for c in ch:
    for i in mun:
        all.append(c + i)

Но кажется есть какой-то более кошерный вариант, не так ли?
botinag
itertools.product()
kampella
botinag
itertools.product()
Спасибо, уже нашел. Также можно делать так:

all = [ c + i for c in ch for i in num]
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB