1/7
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
reverse a string via string slicing
reverse a string in python.
my_string[???]
my_string[::-1]
enumerate()
target both index and value at index in a list.
for ? , ? in ?
for index, value in enumerate(my_object):
zip()
create a list of tuples consisting of pairs from 2 separate lists.
?(my_list_1, my_list_2)
zip(my_list_1, my_list_2)
.strip()
remove trailing or leading whitepspace/characters
my_string.?()
my_string.strip()
or
my_string.strip(‘char’)
.join()
join items together from an iterable
my_iterable.?()
my_iterable.join()
or
my_iterable.join(‘char’)
list comprehension
rewrite the for loop using list comprehension:
words = ["I", "Love", "Codepath!"]
result = []
for word in words:
if len(word) > 5:
result.append(word)
print(result) # Output: ['Codepath!']
result = [word for word in words if len(word) > 5)]
filter/map/list comprehension
rewrite this filter/map function to use list comprehension:
def squareEvens(nums):
result = []
for x in nums:
if x % 2 == 0:
result.append(x * x)
return result
result [x*x for x in nums if x % 2 == 0]
two pointers
what common cases are most suited for the two pointers technique
problems mentioning substrings