LeetCode Flashcards

1
Q

capitalize only the first letter of the string

A

capitalize()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Operator checks if the item is in the container

A

in

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

removes the key-value pair from dictionary and returns the key-value pair

A

popitem()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

retrieve values of the dictionary

A

values()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

retrieve keys of the dictionary

A

keys()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

returns the stored key-value pairs in a dictionary

A

items()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

returns a new set with items present in one set but not in another

A

difference()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

returns a new set with only common items

A

intersection()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

returns a new set with items from both sets

A

union()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

removes an item from the set

A

remove()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

inserts a new item to a set

A

add()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

counts the amount of a certain item in a list

A

count()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

deletes a specific item from a list

A

remove()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

adds new item to a list

A

append()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Dictionary

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Set

A

an unordered collection with no duplicate items (numbers, strings, etc.); unordered means there is no indexing

17
Q

Tuple

A

an ordered immutable sequence of items (numbers, strings, etc.); immutable means we cannot modify the items in the tuple

18
Q

List

A

an ordered mutable sequence of items (ex: numbers, strings, etc.)

19
Q

Iterate over several iterables in parallel, producing tuples with an item from each one.

A

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’)

20
Q

return True if any element of the iterable is true. If the iterable is empty, return False.

A

any(iterable)

21
Q

returns the absolute value of a number

A

abs(x)
x can be an integer, float

22
Q

returns length (number of items) of an object

A

len()

23
Q

removes the item at the given index from the list and returns the removed item

A

pop(index=-1)

24
Q

returns True if all items in an iterable are true, otherwise it returns False

A

all(iterable)

25
Q

computes the reverse of a given sequence object and returns it in the form of a list

A

reversed(sequence_object)

26
Q

returns an object that contains a counter as a key for each value within an object

A

enumerate(iterable, start=0)

27
Q

string concatenation operator

A

+

28
Q

capitalize only the first letter of the string

A

capitalize()

29
Q

transform all characters in a string into lower case

A

lower()

30
Q

transform all characters in a string into upper case

A

upper()

31
Q

replace substring where it substitutes all occurrences of a specific character sequence in a string with another sequence

A

replace(string to replace, string to replace with)

32
Q

returns the index of the first instance of a character in the string

A

index()

33
Q

join a list of strings together with a defined delimiter

A

join()
ex: ‘ ‘.join(list)

34
Q

split a string into a list of strings with a defined delimiter

A

split()
ex: string.split(‘ ‘)

35
Q

when working data frames columns with a string type, the syntax to access the string methods for the column is

A

df[‘column’].str.<string></string>

36
Q

condition used such that we can apply a method on every other index in an iterable

A

if index%2 == 0