python coding notes Flashcards
how to find where a character is
.index(character)
how to remove something from a list
list.pop(position of char)
different ways to show range
- for i in range
- num for num
different ways to do loops
- for i in
- char for char
how to find the number of time something occurs in a list
.occur()
how to sort list
- sorted(list)
- list.sort()
how to find length of something
len()
how to insert an element into a specific index of a list
list.insert()
how to skip numbers when doing range
- add a third input, eg range(2,9,2) would output 2,4,6,8
how to slice lists
list[start:end]
how to see how many times an element occurs in a string or list
.count
how to remove duplicates in a list
use list(set())
what is a tuple
a data structure that allows us to store multiple pieces of data inside of it
- the elements, the order of the elements and how many elements there are cannot be changed
- they are immutable, can’t be edited
what does zip() do
takes two or more list as inputs and returns an object that contains a list of pairs. each pair contains one element from each of the inputs
what is indefinite iteration
where the number of times the loop is executed depends on how many times a condition is met