The if statement below has a problem in it somewhere and I can not figure it out. Any conventions or method misuses that might be causing it to not function right? checkList is a user inputed sentence and lis is a large list of words.
def realCheck(checkList):
string = "".join(checkList)
print string
wordList = string.split()
if match(wordList, lis).sort(key=str.lower) == wordList.sort(key=str.lower):
return True
else:
return False
If checkList is a string, then there
is no need for
"".join(checkList).It just gives you back the same
string:
The first line,
string =has the wrong"".join(checkList)
indentation. Move it back to be
flush with the other lines in the
definition.
Don’t name a variable
string. Itoverrides the standard Python module
of the same name.
Presumably
match(wordList, lis)returns a list. The sort method
sorts the list, and returns
None.Since
None == NoneisTrue,is always true.
More likely, what you want is
Unlike the
sortmethod, thesorted function returns the
sorted list.
As Alex Martelli points out,
always has the same truth value as
So using
str.loweras thekeyfor sorting (rather than as a
transformation before comparing with
==) is probably not what you want.The statement
can be simplified to