Skip to content

Commit cb67066

Browse files
Anagram and reverse string
1 parent dca6623 commit cb67066

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

Anagram.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
def anagram(input1, input2):
3+
input1 = input1.replace(" ","").lower()
4+
input2 = input2.replace(" ","").lower()
5+
if sorted(input1) == sorted(input2):
6+
return True
7+
else:
8+
return False
9+
10+
11+
print(anagram("rat", "art"))
12+
print(anagram("alert", "alter"))
13+
print(anagram("Slot machines", "Cash lost in me"))

ReverseString.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Reverse the words in sentence
2+
def word_flipper(our_string):
3+
inputList = our_string.split(" ")
4+
reverseList = []
5+
for word in inputList:
6+
reverse = ""
7+
for i in range(0, len(word)):
8+
reverse += word[len(word)-1-i]
9+
reverseList.append(reverse)
10+
reverseString = " ".join(reverseList)
11+
return reverseString
12+
# print(word_flipper("This is one small step for ..."))
13+
print ("Pass" if ('retaw' == word_flipper('water')) else "Fail")
14+
print ("Pass" if ('sihT si na elpmaxe' == word_flipper('This is an example')) else "Fail")
15+
print ("Pass" if ('sihT si eno llams pets rof ...' == word_flipper('This is one small step for ...')) else "Fail")

0 commit comments

Comments
 (0)