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
此代码工作正常,但它似乎产生一个额外的列表。输出看起来像这样:Python列表函数生成1个额外列表
[[ [ 'Geodude', '40', '80', '摇滚', '战斗'],
[ '的Raichu', '60', '90' , '电', '正常'],
[ '傀儡', '80', '120', '摇滚', '战斗'] ]]
强劲的括号是多余的和我不能找不到哪一行产生额外的列表。
是啊你对吧谢谢你 –