LIST and ARRAY in PYTHON Flashcards

1
Q

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

A

lists and arrays

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

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

A

Python Arrays

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Accessing an element in a __ ___ is the same as an Array because a List is actually a dynamic array

A

Python List

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

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.

A

list

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

A list can be created using

A

[] containing data values

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

is a vector containing homogeneous elements i.e. belonging to the same data type. Elements are allocated with contiguous memory locations.

A

array

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

by using the array() function of the array module and see its type using the

A

type() function.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Can consist of elements belonging to different data types

A

List

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Only consists of elements belonging to the same data type

A

Array

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

No need to explicitly import a module for the declaration

A

list

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Can directly handle arithmetic operations

A

array

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Cannot directly handle arithmetic operations

A

list

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Need to explicitly import the array module for declaration

A

array

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Greater flexibility allows easy modification (addition, deletion) of data

A

list

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Preferred for a shorter sequence of data items

A

list

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Preferred for a longer sequence of data items

A

array

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Less flexibility since addition, and deletion has to be done element-wise

18
Q

The entire list can be printed without any explicit looping

19
Q

Consume larger memory for easy addition of elements

20
Q

A loop has to be formed to print or access the components of the array

21
Q

Nested ___ can be of variable size

22
Q

Comparatively more compact in memory size

23
Q

Nested __ has to be of same size.

24
Q

for counting a particular element in the list

25
sort the complete list
sort()
26
gives maximum of the list
max()
27
gives minimum of the list
min()
28
gives sum of all the elements in list for integer list
sum()
29
gives first index of the element specified
index()
30
adds the element to the end of the list
append()
31
removes the element specified
remove()
32
are specifically used to store a collection of numeric elements that are all of the same type
Arrays
33
are more flexible than arrays in that they can hold elements of different types (integers, strings, objects, etc.)
Lists
34
my_list = [1, 2, 2, 3] my_set = {1, 2, 2, 3} # Output will be {1, 2, 3}
list can contain duplicate element while set does not support operations that depend on sequence
35
An unordered collection of key-value pairs
Dictionary
36
Used to remove the first occurrence of a specific value from a list. Does not return the removed element. Raises a ValueError if the specified value is not found.
remove()
37
Removes an element at a specific index and returns it. If no index is specified, __ removes and returns the last item in the list. Raises an IndexError if the specified index is out of range.
pop or pop()
38
is a linear list of elements. It is like a single row of data, where each element can be accessed using a single index.
one-dimensional array
39
can be thought of as a table or a matrix with rows and columns. It requires two indices to access an element: one for the row and one for the column.
two-dimensional array
40
extends beyond two dimensions, requiring more than two indices to access its elements. The concept generalizes from 1D and 2D arrays to higher dimensions, such as 3D, 4D, etc.
multidimensional array