马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 Stubborn 于 2019-3-7 00:45 编辑
怎么样可以打印出修改前,和修改后的值
如下是我想要的结果print(deal) #打印这个 [['黑桃', '11'], ['方块', '12'], ['梅花', '9']]
print(deal1) #打印这个[['黑桃', 'J'], ['方块', 'Q'], ['梅花', '9']]
poker_dict = {"11":"J","12":"Q","13":"K","14":"A"}
deal = [['黑桃', '11'], ['方块', '12'], ['梅花', '9']]
deal1 = [x for x in deal]
for dea in deal:
if dea[1] in poker_dict:
print("修改前:",dea)
dea.insert(1, poker_dict[dea[1]]),dea.pop()
print("修改后:",dea)
# poker_dict[dea[1]]
print(id(deal))
print(id(deal1))
print(deal)
print(deal1)
运行结果:修改前: ['黑桃', '11']
修改后: ['黑桃', 'J']
修改前: ['方块', '12']
修改后: ['方块', 'Q']
39252104
30989832
[['黑桃', 'J'], ['方块', 'Q'], ['梅花', '9']]
[['黑桃', 'J'], ['方块', 'Q'], ['梅花', '9']]
修改后这样的:可以获取到我在看看有木有这么麻烦先:poker_dict = {"11":"J","12":"Q","13":"K","14":"A"}
deal = [['黑桃', '11'], ['方块', '12'], ['梅花', '9']]
deal1 = [[x[0]] for x in deal]
for dea in range(len(deal)):
if deal[dea][1] in poker_dict:
deal1[dea].append(deal[dea][1])
deal[dea].insert(1, poker_dict[deal[dea][1]]),deal[dea].pop()
else:
deal1[dea].append(deal[dea][1])
print(id(deal))
print(id(deal1))
print(deal)
print(deal1)
|