+ 1

Lists

What is the purpose of having two brackets around a list? For example List = [[a, b, c]]

18th May 2020, 6:34 AM
Zach Janzen
4 Respuestas
+ 3
Let me give you some examples. lst = [1, 2, 3] list = [[1, 2, 3]] lst has three elements, but list has 1. lst.append(list[0]) now, lst = [1, 2, 3, [1,2,3]] so, it has 4 elements now. Hope it helped
18th May 2020, 6:41 AM
M Tamim
M Tamim - avatar
+ 1
Your example is a list within a list = a nested list: The inner list contains a, b, c while the outer list contains the inner list. [[a, b], c] In thos example, the outer list contains a list (containing a and b) and c
18th May 2020, 6:43 AM
Lisa
Lisa - avatar
0
points=[[3,7],[2,3],[4,8]] could be a list of points with x and y coordinates.
18th May 2020, 6:40 AM
GeorgeT
0
wow. this community is awesome. thanks everyone.
18th May 2020, 7:02 AM
Zach Janzen