Is there a way to make several similar types of strings at once in Python?

Asked 2 years ago, Updated 2 years ago, 46 views

For example, 'AA' , 'AB', 'AC', 'AD' .... 'BA', "BB' ... "ZY' , "ZZ" Can you make several strings of a similar type at once in this way? It's hard because it's my first time programming<

python3 string

2022-09-22 19:44

1 Answers

import itertools

list(itertools.product('ABCD', repeat=2))
Out[34]: 
[('A', 'A'),
 ('A', 'B'),
 ('A', 'C'),
 ('A', 'D'),
 ('B', 'A'),
 ('B', 'B'),
 ('B', 'C'),
 ('B', 'D'),
 ('C', 'A'),
 ('C', 'B'),
 ('C', 'C'),
 ('C', 'D'),
 ('D', 'A'),
 ('D', 'B'),
 ('D', 'C'),
 ('D', 'D')]

If it's your first time programming, please watch the tutorial and proceed with the pre-learning.


2022-09-22 19:44

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.