range doesn't return a list
in Python3, so range(2, 10) + ["J", "Q", "K", "A"]
doesn't work, but list(range(2, 10)) + ["J", "Q", "K", "A"]
does. You can also use itertools.chain to concatenate iterables:
from itertools import chain
chain(range(2, 10), ["J", "Q", "K", "A"])
# or even shorter:
chain(range(2, 10), "JQKA") # as strings themselves are iterables
# so this comprehension will work
deck = [
(value, suit)
for value in chain(range(2, 10), "JQKA")
for suit in "HCDS"
]
The nested comprehension does, of course, constitute a cartesian product which you can also use a util for:
from itertools import product
deck = list(product(chain(range(2, 10), "JQKA"), "HCDS"))