Python arrays
What is the difference between an array and a list?
python - What does [:] mean? - Stack Overflow
Numpy array is the worst part of python.
Videos
I'm following roadmap.sh/python to learn python. I'm at the DSA section.
I understand the concept of arrays in DSA, but what I don't understand is how to represent them in Python.
Some tutorials I've seen use lists to represent arrays (even though arrays are homogeneous and lists are heterogeneous).
I've seen some other tutorials use the arrays module to create arrays like array.array('i') where the array has only integers. But I have never seen anybody use this module to represent arrays.
I've also seen some tutorials use numpy arrays. Which I don't understand their difference from the normal arrays module.
What should I use to represent arrays?
So far I've solved a couple of arrays exercises using Python lists.
It is an example of slice notation, and what it does depends on the type of population. If population is a list, this line will create a shallow copy of the list. For an object of type tuple or a str, it will do nothing (the line will do the same without [:]), and for a (say) NumPy array, it will create a new view to the same data.
It might also help to know that a list slice in general makes a copy of part of the list. E.g. population[2:4] will return a list containing population[2] and population[3] (slicing is right-exclusive). Leaving away the left and right index, as in population[:] they default to 0 and length(population) respectively, thereby selecting the entire list. Hence this is a common idiom to make a copy of a list.