calling a function from another function in python
Posted
by
user1040503
on Stack Overflow
See other posts from Stack Overflow
or by user1040503
Published on 2011-11-28T17:14:05Z
Indexed on
2011/11/28
17:50 UTC
Read the original article
Hit count: 264
I have written this function that takes to strings in order to see if they are anagrams:
def anagram_check(str_x, str_y):
x = string1.replace(" ","")
y = string2.replace(" ","")
lower1 = x.lower()
lower2 = y.lower()
sorted1 = sorted(lower1)
sorted2 = sorted(lower2)
if sorted1 == sorted2:
return True
else:
return False
this function works fine, the problem is that now I need to use this function in another function in order to find anagrams in a text file. I want to print a list of tuples with all the anagrams in it. this is what i have done so far
def anagrams_finder(words_num):
anagrams = []
f = open("words.txt")
a = list(f)
list1 = ([s.replace('\n', '') for s in a])
list2 = ([i.lower() for i in list1])
list3 = list2[0:words_num] #number of words from text that need to be checked.
for i in list3:
....
I tried using for loops, while loops, appand.... but nothing seems to work. how can I use the first function in order to help me with the second? Please help...
© Stack Overflow or respective owner