2d array of lists in python

前端 未结 6 1307
北海茫月
北海茫月 2021-01-12 07:05

I am trying to create a 2d matrix so that each cell contains a list of strings. Matrix dimensions are known before the creation and I need to have access to any element from

6条回答
  •  自闭症患者
    2021-01-12 07:34

    Hey guys not sure if this is helpful or not but this is how I generated a 2d list with python3.4 hope this is helpful

    list=[]
    list1=[]
    list2=[]
    list3=[]
    answer1='yes'
    answer2='yes'
    answer3='yes'
    
    while answer1=='yes':
        item1=input("Please input a list element for your first list:")
        answer1=input("Do you want to continue:")
        list1.append(item1)
    
    while answer2=='yes':
        item2=input("Please input a list element for your second list:")
        answer2=input("Do you want to continue:")
        list2.append(item2)
    
    while answer3=='yes':
        item3=input("Please input a list element for your third list:")
        answer3=input("Do you want to continue:")
        list3.append(item3)
    
    list.append(list1)
    list.append(list2)
    list.append(list3)
    
    print(list)
    

提交回复
热议问题