Aim
I would like to generate a sequence as list
in python
, such as:
['s1a', 's1b', 's2a', 's2b', ..., 's10a', 's10b']
Properties:
- items contain a single prefix
- numbers are sorted numerical
- suffix is alternating per number
Approach
To get this, I applied the following code, using an xrange
and comprehensive list approach:
# prefix
p = 's'
# suffix
s = ['a', 'b']
# numbers
n = [ i + 1 for i in list(xrange(10))]
# result
[ p + str(i) + j for i, j in zip(sorted(n * len(s)), s * len(n)) ]
Question
Is there a more simple syntax to obtain the results, e.g. using itertools
?
Similar to this question?