Skip to content

Commit 66c197f

Browse files
committed
fixed the flake8 errors
1 parent 0c17310 commit 66c197f

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

string-formatting/string-reversal.py

+7-11
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,37 @@
11
# ------------------------------------------------------------------------------------
22
# We're going to look at a few different ways that you can reverse the structure of a string .
3-
# Let's begin
3+
# Let's begin.
44
# ------------------------------------------------------------------------------------
55

66
# Single Words , A string is an iterable and anything within these --> ""
77
# 1. The built-in reverse method
88
# This method is used on iterables , commonly on lists and strings
9-
# Example of a function that reverses a string
9+
# Example of functions that reverse a string.
1010
def reverseString(word):
1111
reversedWord = "".join(reversed(word))
1212
return reversedWord
1313
'''
1414
Let's break down what's above:
1515
Remember that all strings are immutable but iterable. So if that's the case , we can't use the .reverse() function like we could on a list.
1616
So we iterate through each letter and use the reversed() function . Now since the reversed() function return an iterable;a list .
17-
We use the join() to concatenate the letters and then we return the reversed String
17+
We use the join() to concatenate the letters and then we return the reversed String.
1818
'''
19-
#2. The reverse slice method
19+
# 2.The reverse slice method
2020
# This method also works on iterables too.
2121
# Let's use the same example with this method too
22-
def reverseString(word):
22+
def backString(word):
2323
reversedWord = word[::-1]
2424
return reversedWord
2525
'''
2626
Let's break this down as well:
2727
The slicing technique is used to get a certain portion of string and using the starting and ending index values.
2828
e.g [a:b], this slices from position to position before b ; so b-1 . What we don't commonly use is the third option of [a:b:c] <-- C.
29-
What c does is specify the number of characters to jump or skip over . So if c == 2 , we're gonna skip over 2 characters .
30-
But if c == -1 , this specifies that the string begins from the back .
31-
We commonly use -1 when we want the last letter or character in a string e.g word = "pet" , word[-1] == t.
29+
What c does is specify the number of characters to jump or skip over . So if c == 2 , we're gonna skip over 2 characters .But if c == -1,this specifies that the string begins from the back.
30+
We commonly use -1 when we want the last letter or character in a string e.g word = "pet",word[-1] == t.
3231
Back to the function , if we don't specify the starting and end values , the computer just assumes it's the whole string .
3332
So e.g [a:] this is from a to the last , [:b] from the first to b , [a::c] from a to the last every c characters , [:b:c] from the first to b every c characters .
3433
So [::-1] means from the first to last in reverse .
3534
'''
3635

37-
38-
3936
# ------------------------------------------------------------------------------------
4037
# The format is the same even for sentences : So write a function that reverses the sentence "I love ketchup".
41-
# ------------------------------------------------------------------------------------

0 commit comments

Comments
 (0)