Jun 3, 2021

Python Array Vs List

 Python Array Vs List

ListArray
Heterigenous elements
E.g, [1, 2, [3, 4], 5, 6]
Homogenous elements
numbers = array.array('i', [1, 2, 3])
Explicitly define type of elements while defining (i - means integers
Use lot more spaceUse less spcace compared lists
List contains pointers to different objectsLike C language arrays, with a pointer pointing to first element & rest are allocated in continuous memory
More flexible keeping different structures of dataLess flexible
Less efficient in storing & manipulatingMore efficient in storing & manipulating
Used when your collection grow & shrink in time efficient manner & manage lot of data types in a listUsed when you perform lot of computationally intensive math operations
Numpy arrays are more suited for mathematical operations



No comments:

Post a Comment