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

A

array

18
Q

The entire list can be printed without any explicit looping

A

list

19
Q

Consume larger memory for easy addition of elements

A

list

20
Q

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

A

array

21
Q

Nested ___ can be of variable size

A

lists

22
Q

Comparatively more compact in memory size

A

array

23
Q

Nested __ has to be of same size.

A

arrays

24
Q

for counting a particular element in the list

A

count()

25
Q

sort the complete list

A

sort()

26
Q

gives maximum of the list

A

max()

27
Q

gives minimum of the list

A

min()

28
Q

gives sum of all the elements in list for integer list

A

sum()

29
Q

gives first index of the element specified

A

index()

30
Q

adds the element to the end of the list

A

append()

31
Q

removes the element specified

A

remove()

32
Q

are specifically used to store a collection of numeric elements that are all of the same type

A

Arrays

33
Q

are more flexible than arrays in that they can hold elements of different types (integers, strings, objects, etc.)

A

Lists

34
Q

my_list = [1, 2, 2, 3]
my_set = {1, 2, 2, 3} # Output will be {1, 2, 3}

A

list can contain duplicate element while set does not support operations that depend on sequence

35
Q

An unordered collection of key-value pairs

A

Dictionary

36
Q

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.

A

remove()

37
Q

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.

A

pop or pop()

38
Q

is a linear list of
elements. It is like a single row of data,
where each element can be accessed
using a single index.

A

one-dimensional array

39
Q

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.

A

two-dimensional array

40
Q

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.

A

multidimensional array