Remember: - Lists can be used to group different values together - it’s just a collection of things. - You can make a list in Python by putting different things in a box of brackets [] separated by commas:
Guess what? You can also make lists of lists!! These are called 2D lists in Python.
You can make a 2D list like this:
# list number 1fruit = ['apple', 'banana', 'grape', 'mango']# list number 2veggies = ['lettuce','carrot','cucumber','beet']# create 2D listfood = [fruit, veggies]# print 2D listprint(food)
Is this what you expected? Since food is a list that contains two list objects, the length of food is 2.
# make a list of meats and save it to the variable meatmeat = ['chicken','beef','fish','pork']# add another list to food with meatfood.append(meat)# print foodprint(food)