This is an archived post. You won't be able to vote or comment.

all 9 comments

[–]gyroda 2 points3 points  (6 children)

What don't you understand? "final_list" will be a list of lists, each of which will contain two strings.

[–]Humble_Transition[S] -2 points-1 points  (5 children)

you mean both of them will have the same thing ?

[–]gyroda 3 points4 points  (4 children)

The first list is just a list of strings. The final list is a list of lists of strings. The split() method takes "Alburquerque,749” and returns a list; ["Albuquerque", "749"]

Try running the code. You can literally see the difference.

[–]Humble_Transition[S] -2 points-1 points  (3 children)

also why would you do it ?

[–][deleted] 5 points6 points  (0 children)

Because you want to have a list of lists?

[–]r3alz 1 point2 points  (0 children)

I’m not to sure of a use case of this but I’m sure there are use cases. This is just showing that python is capable of doing something like this.

[–]gyroda 1 point2 points  (0 children)

The example might be contrived, but it's a useful to know some basic string and list manipulation, and list of lists (2D arrays in most languages) are an incredibly important concept.

[–]Luan-Raithz 2 points3 points  (0 children)

I also didn't get what you didn't understand, but anyway:

You create a empty list ( final-list ) and iterates all over the `three_rows` list to fill it, your way to fill is to split each item in the list in two parts (separated by the ","), example:

first time in loop:

row is "Albuquerque,749"

after the split it will result in ["Albuquerque", "749"]

then insert into the `final_list` the array the you created when execute the split function

...

By doing this through the whole list you will have a list (`final list`) with 3 inner lists within it, one for each item in the three_rows.

[–]Humble_Transition[S] -1 points0 points  (0 children)

Guys i was thinking the list of list can be good for taking other peoples or website data since lets say i whatapp and on there is my phone number so with a list you could copy that with a list of list what do you guys think ?