How do I make a flat list out of a list of lists? - Stack Overflow If your list of lists comes from a nested list comprehension, the problem can be solved more simply directly by fixing the comprehension; please see How can I get a flat result from a list comprehension instead of a nested list? The most popular solutions here generally only flatten one "level" of the nested list See Flatten an irregular (arbitrarily nested) list of lists for solutions that
slice - How slicing in Python works - Stack Overflow The first way works for a list or a string; the second way only works for a list, because slice assignment isn't allowed for strings Other than that I think the only difference is speed: it looks like it's a little faster the first way Try it yourself with timeit timeit () or preferably timeit repeat ()
What is the difference between list and list [:] in python? When reading, list is a reference to the original list, and list[:] shallow-copies the list When assigning, list (re)binds the name and list[:] slice-assigns, replacing what was previously in the list Also, don't use list as a name since it shadows the built-in