Week 12: Arrays Flashcards

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

T or F:
Variables need to be numbered when in Lists.

A

False.
They are automatically numbered (called index).

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

How to create a new List

A

Variable_list_name = [“variable1”, “variable 2”, “variable 3”]

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

T or F:
Lists can comprise of mixed types of data.

A

True.
Numbers and texts.

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

How to add a variable to an existing list?
How to add more than 1?

A

variable_list = [“variable4”, “variable5”]
variable_list.append(“variable6”)
______
variable_list.extend() or +

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

Using an existing list, how to add more variables for a bigger/new/other list.

A

Longer_variable_list=variable_list_name + [“variable4”, “variable5”]

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

To add a new variable in a list in a specific spot (index).

A

variable_list_name.insert(2, “variable 6”)

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

Assign a new value to an element (replace).

A

variable_list_name [2] = “variable 7”

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

How to create an empty/editable list.

A

new_list = []
To add to the new list;
new_list = new_list + [“variable1”]

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

To copy some elements from 1 list into another.

A

newest_list = variable_list_name [2:5]
It details how many elements will be assigned to the new list, this case is 3

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

What is its meaning, to take slices?

A

Copy, not cut from lists

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

When the last element of the slice is the last of the original list, can omit the second number.

A

newest_list = variable_list_name [2:]

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

T or F:
Index’s count 0 as the 1st #

A

True.
Example, 0-5 would be 0, 1, 2, 3, 4

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

How to delete an element in a list?

A

del variable_list_name [index number]
The index moves to fill the gap of that, so if you deleted index 0, the next in line would take its place.
OR
Variable_list_name.remove(“variable3”)

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

How to remove an element from 1 list and place at the end of another.

A

Newer_list = variable_list_name.pop(index number)
OR
Newer_list.append(variable_list_name.pop(index number))

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

How to remove an element from 1 list and place it in a specific index of another list.

A

Newer_list.insert((spot), list_name.pop(1))
Example, task of index 3 (spot 2) will be added removed and added to another list:
tasks_accomplished.insert(1, tasks.pop(1))

17
Q

What is a tuple()?

A

Non-editable/stable list.

18
Q

How do you find a variable in a list?

A

for loop.
Example:
city_to_check = “Tucson”
new variable is a_clean_city
cleanest_cities = [“we”, Tucson”, “honolulu”]

for a_clean_city in cleanest_cities:
if city_to_check == clean_cities:
print(“Its one of the cleanest cities”)

19
Q

How can you stop loops?

20
Q

How to search through a specific range of index numbers?

A

for x in range(1,11)
print(x)

0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10

21
Q

How to search for a specific variable in a list?

A

for num in nums:
if nums == 3:
print(“found 3!”)
break
print(num)

1, 2, found 3!