Python Array Vs List
List | Array |
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 space | Use less spcace compared lists |
List contains pointers to different objects | Like C language arrays, with a pointer pointing to first element & rest are allocated in continuous memory |
More flexible keeping different structures of data | Less flexible |
Less efficient in storing & manipulating | More efficient in storing & manipulating |
Used when your collection grow & shrink in time efficient manner & manage lot of data types in a list | Used when you perform lot of computationally intensive math operations |
Numpy arrays are more suited for mathematical operations |
No comments:
Post a Comment