简体   繁体   中英

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)

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM