python syntax

0.0(0)
studied byStudied by 0 people
full-widthCall with Kai
GameKnowt Play
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/7

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

8 Terms

1
New cards

reverse a string via string slicing
reverse a string in python.
my_string[???]

my_string[::-1]

2
New cards

enumerate()
target both index and value at index in a list.
for ? , ? in ?

for index, value in enumerate(my_object):

3
New cards

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)

4
New cards

.strip()
remove trailing or leading whitepspace/characters
my_string.?()

my_string.strip()
or
my_string.strip(‘char’)

5
New cards

.join()
join items together from an iterable

my_iterable.?()

my_iterable.join()
or
my_iterable.join(‘char’)

6
New cards
<p><strong>list comprehension</strong><br>rewrite the for loop using list comprehension:<br><br>words = ["I", "Love", "Codepath!"]
result = []

for word in words:
    if len(word) &gt; 5:
        result.append(word)

print(result) # Output: ['Codepath!']
<br></p>

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

7
New cards
<p><strong>filter/map/list comprehension</strong><br>rewrite this filter/map function to use list comprehension:<br><br>def squareEvens(nums):</p><p>&nbsp; &nbsp; result = []</p><p>&nbsp; &nbsp; for x in nums:</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if x % 2 == 0:</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;result.append(x * x)</p><p>&nbsp; &nbsp; return result</p>

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]

8
New cards

two pointers
what common cases are most suited for the two pointers technique

problems mentioning substrings