Composted Variables (list(2)) Flashcards

1
Q

How can u put a list inside another?

A

list1 = list()
list1.append(list2[:]) ~~ you’ll be adding a list (list2) to the list1 and u need to put the index [:] with two dots so it gathers everything inside it.
OR
list1 = [[‘tex1’, 1] , [‘text2’, 2,] , [‘text3’, 3]] ~~ use the key [] to gather all other keys [] witch representes other lists.

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

How to print something inside a group of lists?

A

~~printing two indexes.
print(list[0][0])
first [0] is the first list.
second [0] is the first word in it.

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

How to print all the elements of a group at once?

A

~~ for o in list1:

print(o[element u want])

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

What happens if you use len() in a list?

A

The value returned is equal to the number of elements in the list.

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

What are methods?

A

Orientation to objects resources, a function to the object.

Always its name after the name of the object (example : a.append()

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

What is the extend function and how to use it?

A

A function that adds a list to another (limited to it).

name + .extend([element])

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

Can you add two lists inside one?

How?

A

a = [ [], [] ]

By adding a key and having two more inside of it separated by a coma.

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

How to use lists as queues?

A

The inclusion is realized at the end, and the exclusion at the beginning.
FIFO - First In First Out

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

What does the command pop do? (on a list)

A

Exclude from the list and hold/return its value.

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

How to use lists as piles?

A

Last element to be added is the first element to get out (be removed).
LIFO - Last In First Out

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

What’s the difference between a pile and a queue?

A

On the queue, the first element to be removed is the first one, on the pile, is the last one (that was added).

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

How to limit numbers to be added to a list?

A

z = list()
c = int(input(‘Type the numbers: ‘))
if c not in z:
z.append(c)

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