Isnt this an array | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Isnt this an array

so this is technically an array, isn't it

26th Jul 2018, 10:20 PM
The Tech Lord
The Tech Lord - avatar
4 Answers
+ 3
They're similiar, but you can't change the size of an array where as elements of a list can easily be added and removed. There are also library function like sort() and reverse() for lists which can make things a lot easier.
26th Jul 2018, 10:57 PM
Theresa
Theresa - avatar
+ 3
Oh, no. List are not arrays at all. They both are collections, but they are stored in a computer memory in a quite different way. Arrays are stored by just an address if it's first element. The access to a certain array element is got by specifying an offset for the element from the first one as array index. E.g. we have an array of ints. Each int occupies 4 bytes in memory. To get the 5th element of array we need to add 4(length of int)x4(the offset) to the address of the first element and there will be the element we want. That's why, btw, the array indexing starts from 0. Arrays are good for random access to every element, but are not resizable, because the memory is allocated to an array when its created. If we "resize" an array, we actually create a new array and copy to it the data from an old one.
27th Jul 2018, 4:04 AM
Дмитро Іванов
Дмитро Іванов - avatar
+ 1
List is a collection of elements, each of which stores an object of data and a link to next and, sometimes, a previous element. List can be easily resized, because the memory is allocated to each element separately and they can be easily iterated by links, but they are not to good for random access, because to get to the nth element of list you should go step by step from 0 to nth element.
27th Jul 2018, 4:06 AM
Дмитро Іванов
Дмитро Іванов - avatar
0
I contradict the statement that lists aren't arrays. what is called as arrays in other programming languages is actually called as list in python. The concept of Data structures is same here.
7th Aug 2018, 7:33 PM
Deepak Pandit
Deepak Pandit - avatar