LeetCode Flashcards
capitalize only the first letter of the string
capitalize()
Operator checks if the item is in the container
in
removes the key-value pair from dictionary and returns the key-value pair
popitem()
retrieve values of the dictionary
values()
retrieve keys of the dictionary
keys()
returns the stored key-value pairs in a dictionary
items()
returns a new set with items present in one set but not in another
difference()
returns a new set with only common items
intersection()
returns a new set with items from both sets
union()
removes an item from the set
remove()
inserts a new item to a set
add()
counts the amount of a certain item in a list
count()
deletes a specific item from a list
remove()
adds new item to a list
append()
Dictionary
a collection of key-value pairs where keys are unique and immutable; key has a unique correspondence to its value, but not the other way around
Set
an unordered collection with no duplicate items (numbers, strings, etc.); unordered means there is no indexing
Tuple
an ordered immutable sequence of items (numbers, strings, etc.); immutable means we cannot modify the items in the tuple
List
an ordered mutable sequence of items (ex: numbers, strings, etc.)
Iterate over several iterables in parallel, producing tuples with an item from each one.
zip(*iterables, strict=False)
strict: if set to True, checks that the lengths of iterables are identical
ex:
for item in zip([1, 2, 3], [‘sugar’, ‘spice’, ‘everything nice’]):
… print(item)
…
(1, ‘sugar’)
(2, ‘spice’)
(3, ‘everything nice’)
return True if any element of the iterable is true. If the iterable is empty, return False.
any(iterable)
returns the absolute value of a number
abs(x)
x can be an integer, float
returns length (number of items) of an object
len()
removes the item at the given index from the list and returns the removed item
pop(index=-1)
returns True if all items in an iterable are true, otherwise it returns False
all(iterable)