Last active
December 19, 2015 09:39
-
-
Save lplume/5934912 to your computer and use it in GitHub Desktop.
italian palindrome sentence check (switch accent sugar)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
# TODO: input like "a'a'" | |
f = sys.argv[1].replace(" ","").lower() | |
o = f.find("'") | |
if o > 0: | |
r = (f[:o-1]+f[o-1:o+1][::-1]+f[o+1:]) | |
else: | |
r = f | |
print f == r[::-1] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
f = [x for x in sys.argv[1] if x != "'" and x != ' '] | |
f == f[::-1] |
thanks a lot! 2nd version updated!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Instead of the find you can use filter
filter( lambda x: x != "'", sys.argv[1])
or list comprehension
[x for x in sys.argv[1] if x != "'"]