1/35
Looks like no tags are added yet.
Looping Array Elements
You can use the for in loop to loop through all the elements of an array.
Print each item in the cars array:
for x in cars:
print(x)
.append() and .insert()
list_name.append(“thing”)
list_name.insert(index, ““)
del format
del list_name[index]
Reverses the order of the list
reverse()
break
exits the loop immediately, and unconditionally ends the loop's operation; the program begins to execute the nearest instruction after the loop's body;
continue
behaves as if the program has suddenly reached the end of the body; the next turn is started and the condition expression is tested immediately.
bubble sort
if my_list[i] > my_list[i + 1]:
swapped = True
my_list[i], my_list[i + 1] = my_list[i + 1], my_list[i]
my_list[start:end]
slice
start
is the index of the first element included in the slice;
end
is the index of the first element not included in the slice.
in
checks if a given element (its left argument) is currently stored somewhere inside the list (the right argument) ‒ the operator returns True in this case.
not in
checks if a given element (its left argument) is absent in a list ‒ the operator returns True in this case.
sort()
mylist.sort()
len()
len(myfirst)
How to display arrays a single time with range()
for i in range(list):
print(list[i])
parameters exist only inside functions in which they have been defined
True
assigning a value to the parameter is done at the time of the function's invocation,
True
parameters live inside functions (this is their natural environment)
True
arguments exist outside functions,
True
return
functions to return a value
[:]
Full list
[start:]
From start to the end
[:stop]
From beginning to stop
[::step]
Every step-th item from start to end
[start:stop:step]
Full control
[::-1]
reverses the list
[::2]
every second item
None
mustn't take part in any expressions
when you assign it to a variable (or return it as a function's result)
when you compare it with a variable to diagnose its internal state.
adding key pairs to dictionary
dictionary['swan'] = 'cygne'
dictionary.update({"duck": "canard"})
Removing a key
del dictionary['dog']
R