def run_counter(card_list, num_cards):
hand = functions1.hand_sample(card_list, num_cards)
hand1 = functions1.hand_shuffle(card_list, num_cards)
srt_hand = sorted(hand)
srt_hand1 = sorted(hand1)
prop_hand = functions1.proper_hand(srt_hand)
prop_hand1 = functions1.proper_hand(srt_hand1)
run1 = 0
i = 0
for count in range(len(srt_hand)-1):
if srt_hand[i] == srt_hand[i+1] - 1:
run1 += 1
run2 = 0
i = 0
for count in range(len(srt_hand1)-1):
if srt_hand1[i] == srt_hand1[i+1] - 1:
run2 += 1
return run1+1, run2+1, prop_hand, prop_hand1我有自己生成的一手牌,并存储在排序列表'srt_hand‘和'srt_hand1’中。我做了一个函数来计算手中游程的长度。我去测试它,但它总是说'if srt_handi == srt_handi+1 - 1:‘是一个不支持的操作数类型。为什么会这样呢?这没有任何意义,因为我索引的是一个整数列表...
我以前用过同样的排序技术,它起作用了(除了它在第一次运行后停止):
run1 = 0
i = 0
while i < len(srt_hand)-1 and run1 < 2:
while i < len(srt_hand)-1 and srt_hand[i] == srt_hand[i+1] - 1:
if srt_hand[i] == srt_hand[i+1]:
i += 1
run1 += 1
i += 1
i += 1
run2 = 0
i = 0
while i < len(srt_hand1)-1 and run2 < 2:
while i < len(srt_hand1)-1 and srt_hand1[i] == srt_hand1[i+1] - 1:
if srt_hand[i] == srt_hand[i+1]:
i += 1
run2 += 1
i += 1
i += 1
return run1+1, run2+1, prop_hand, prop_hand1发布于 2013-11-15 10:07:28
在python3.3中,sorted函数返回一个生成器,因此您不能像在srt_hand[i]中那样对它进行索引(这将引发异常)。
https://stackoverflow.com/questions/19992192
复制相似问题