【发布时间】:2015-12-14 18:37:43
【问题描述】:
def randomly_pokemon_select_function():
from random import randint
import linecache
open_pokedex=open("pokedex.txt","r")
p1_p1=list()
p1_p2=list()
p1_p3=list()
p2_p1=list()
p2_p2=list()
p2_p3=list()
player1_pokemons=list()
player2_pokemons=list()
pokemon_selection=(randint(1,40))
p1_p1.append(linecache.getline("pokedex.txt", pokemon_selection).split())
pokemon_selection=(randint(1,40))
p1_p2.append(linecache.getline("pokedex.txt", pokemon_selection).split())
pokemon_selection=(randint(1,40))
p1_p3.append(linecache.getline("pokedex.txt", pokemon_selection).split())
pokemon_selection=(randint(1,40))
p2_p1.append(linecache.getline("pokedex.txt", pokemon_selection).split())
pokemon_selection=(randint(1,40))
p2_p2.append(linecache.getline("pokedex.txt", pokemon_selection).split())
pokemon_selection=(randint(1,40))
p2_p3.append(linecache.getline("pokedex.txt", pokemon_selection).split())
player1_pokemons.append(p1_p1+p1_p2+p1_p3)
player2_pokemons.append(p2_p1+p2_p2+p2_p3)
open_pokedex.close()
print player1_pokemons
print player2_pokemons
return player1_pokemons,player2_pokemons
这段代码运行良好,但它似乎生成了一个额外的列表。输出如下所示:
[[['Geodude','40','80','摇滚','格斗'],
['Raichu', '60', '90', '电动', '普通'],
['Golem', '80', '120', 'Rock', 'Fighting']]]
强括号是额外的,我找不到哪一行生成了额外的列表。
【问题讨论】:
标签: python list python-2.7