Michael Peterson
Michael Peterson

Reputation: 17

having trouble using operands between a range and list

Any idea why i get this message for the below code? "unsupported operand type(s) for +: 'range' and 'int'"

# Hearts, Spades, Clubs, Diamonds

suits = ['H', 'S', 'C', 'D']
card_val = (range(1, 11) + [10] * 3) * 4
base_names = ['A'] + range(2, 11) + ['J', 'K', 'Q']
cards = []
for suit in ['H', 'S', 'C', 'D']:
cards.extend(str(num) + suit for num in base_names)

deck = Series(card_val, index=cards)

Upvotes: 1

Views: 127

Answers (1)

Zohaib Ijaz
Zohaib Ijaz

Reputation: 22885

I think you are using Python 3 and range() is a generator in python 3. Encapsulate range inside a list. list(range(10))

card_val = (list(range(1, 11)) + [10] * 3) * 4

Upvotes: 2

Related Questions