2017-12-09 11 views
-3

私は私にPythonでリストの未知数を与えるコードの断片を作成した場合:Pythonのループの繰り返しごとに異なる変数を呼び出すにはどうすればよいですか?

list1 = [1,2,3,4] 
list2 = [5,6,7,8] 
list3 = [9,10,11] 

どのように私はその都度個別にこれらのリストのそれぞれを呼び出してループを作成するのですか?:

for e in range(0,3): #number of lists 
    print list"e"#i need help with this part 
+0

あなたはしていません。最初からそれらを作成すべきではありません。 –

+2

リストをリストのリストに入れてください... –

+1

'lists = [[1,2,3,4]、[5,6,7,8]、[9,10,11]]'それから ':リストの中でlのために:print(l) ' –

答えて

0
import random 

def CreateMeLists(): # creates 3 to 12 lists of various sizes randomly 
    for n in range(0,random.randint(3,12)): 
     yield range(random.randint(4,7),random.randint(15,25)) 

listOfList = list(CreateMeLists()) # get some random lists 

for l in listOfList: # for all lists that are 
    print(l) # do something with each lists 
関連する問題