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', '搖滾', '戰鬥'] ]]
強勁的括號是多餘的和我不能找不到哪一行產生額外的列表。
是啊你對吧謝謝你 –