Composted Variables (list(2)) Flashcards
How can u put a list inside another?
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 to print something inside a group of lists?
~~printing two indexes.
print(list[0][0])
first [0] is the first list.
second [0] is the first word in it.
How to print all the elements of a group at once?
~~ for o in list1:
print(o[element u want])
What happens if you use len() in a list?
The value returned is equal to the number of elements in the list.
What are methods?
Orientation to objects resources, a function to the object.
Always its name after the name of the object (example : a.append()
What is the extend function and how to use it?
A function that adds a list to another (limited to it).
name + .extend([element])
Can you add two lists inside one?
How?
a = [ [], [] ]
By adding a key and having two more inside of it separated by a coma.
How to use lists as queues?
The inclusion is realized at the end, and the exclusion at the beginning.
FIFO - First In First Out
What does the command pop do? (on a list)
Exclude from the list and hold/return its value.
How to use lists as piles?
Last element to be added is the first element to get out (be removed).
LIFO - Last In First Out
What’s the difference between a pile and a queue?
On the queue, the first element to be removed is the first one, on the pile, is the last one (that was added).
How to limit numbers to be added to a list?
z = list()
c = int(input(‘Type the numbers: ‘))
if c not in z:
z.append(c)