LIST and ARRAY in PYTHON Flashcards
are the data structures that are used to store multiple items. They both support the indexing of elements to access them, slicing, and iterating over the elements
lists and arrays
Accessing element is fast in __ ___ because they are in a contiguous manner but insertion and deletion is quite expensive because all the elements are shifted from the position of inserting and deleting element linearly
Python Arrays
Accessing an element in a __ ___ is the same as an Array because a List is actually a dynamic array
Python List
in Python is an inbuilt collection of items that can contain elements of multiple data types, which may be either numeric, character logical values, etc. It is an ordered collection supporting negative indexing.
list
A list can be created using
[] containing data values
is a vector containing homogeneous elements i.e. belonging to the same data type. Elements are allocated with contiguous memory locations.
array
by using the array() function of the array module and see its type using the
type() function.
Can consist of elements belonging to different data types
List
Only consists of elements belonging to the same data type
Array
No need to explicitly import a module for the declaration
list
Can directly handle arithmetic operations
array
Cannot directly handle arithmetic operations
list
Need to explicitly import the array module for declaration
array
Greater flexibility allows easy modification (addition, deletion) of data
list
Preferred for a shorter sequence of data items
list
Preferred for a longer sequence of data items
array