1

List:

['a0', 'a1', 'a2', 'a3', 'a4', 'a5', 'a6', 'a7', 
 'b0', 'b1', 'b2', 'b3', 'b4', 'b5', 'b6', 'b7',
 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'c7',
 'd0', 'd1', 'd2', 'd3', 'd4', 'd5', 'd6', 'd7',
 'e0', 'e1', 'e2', 'e3', 'e4', 'e5', 'e6', 'e7',
 'f0', 'f1', 'f2', 'f3', 'f4', 'f5', 'f6', 'f7',
 'g0', 'g1', 'g2', 'g3', 'g4', 'g5', 'g6', 'g7',
 'h0', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'h7']

I've tried using itertools but have not been successful,

My code currently to generate the above list is:

dmi_list = []
for i in range(ord('a'), ord('i')):
  for j in range(0,8):
     dmi_list.append(chr(i)+str(j))

print(dmi_list)
  • 2
    The corresponding itertools function would probably be [product](https://docs.python.org/3/library/itertools.html#itertools.product), but i usually would keep your original code. – sascha Jul 19 '17 at 23:30

2 Answers2

3

Simple list comprehension would be my choice:

>>> [x + y for x in 'abcdefgh' for y in '01234567']
['a0',
 'a1',
 'a2',
 'a3',
 ...
 'h7']
wim
  • 338,267
  • 99
  • 616
  • 750
0

I would simply write

 [letter + number for letter in 'abcdefgh' for number in '01234567']
amalloy
  • 89,153
  • 8
  • 140
  • 205