1/18
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
Tuples
an immutable and ordered sequence of elements; element types can be mixed; represented with parentheses (); can perform indexing, concatenation, and len() on them
empty tuple
variable = ()
singleton tuple
tuple of one character/element
for loops with tuples
iterate over the tuple object at each position
Lists
ordered and mutable sequence of info/ elements that are usually homogenous, accessible by index; denoted by square brackets []; can index and len()
Iterating over a list
compute the sum of elements of a list; common pattern, iterate over list elements; indexed 0 to len(variable)-1 and range(n) goes from 0 to n-1
L.append(element)
add elements to end of list (mutates the list)
L.extend (some_list)
combines lists together
del(L[index])
delete element at a specific index
L.pop()
remove element at end of list and returns the removed element
L.remove (element)
removes a specific element’s 1st occurrence in a list (if not there then results in error)
list(s)
converts string to list by returning a list with every character from s with an element in L
s.split
splits a string on a character parameter, splits on spaces if called without a parameter
‘‘.join(L)
turn a list of characters into a string, can give a character in quotes to add char between every element
sorted()
returns sorted list, does not mutate (creates new list that must be assigned to new variable)
.sort()
mutates list by placing list elements in order (returns nothing)
.reverse()
mutates list by reversing order of list elements
alias
another variable name that gives same value as another variable (if one variable changes both changes)
List 1 = ListA[:]
clones a list by creating a new list and copy every element