DATA STRUCTURES Flashcards
How to insert and item
list.insert(i, x)
where i is the Index x is the value
how to remove first item
list.remove(x)
where x must math first item
how to remove any item from any position given
list.pop(i)
whre i is the index
how to remove the last item of a list with pop function
list.pop()
empty function
How to return the index value of an item
list.index(x)
x is the value of the item
How to count how many values are the same
list.count(x)
where X is the value to count, must have a value
How to reverse the list
list.reverse()
list will be reverse
How to sort a list
list.sort()
ascending = default
decending = reverse = True
Dictionaries - what is the syntax
dic = { key : value , key: value}
How to remove an entry from a dictionary
dic.pop( ‘Key’ )
only the key is needed
How to add an entry to a dictionary
dic.update( { Key : value})
How to sort dictionary by Keys - ascending and descending
sorted( dic ) – ascending
sorted( dic , reverse=True) –descending
What is a TUPLE
a data structure that can contain multiple data types, but cannot be edited
What is TUPLE syntax
mytup = ( value, value, value)
What is a SET
a data structure that holds UNIQUE VALUES
any type of data but must be equal