Does anyone know how i can fix my Palindrome program?
s = raw_input('Enter a String: ')
punctuation = '%$!*.,-:? ;()\'\"\\'
i = 0
h = 0
t = 0
p = ''
z = 0
while s!= ' ':
while i <= len(s) - 1:
punct = s[i]
if punctuation.find(punct) == -1:
p = p + punct
i = i + 1
t = p.lower()
t[h] == t[len(t)-1-h] 24 12805
On 13 Nov 2003 03:31:35 GMT, Runic911 wrote: Does anyone know how i can fix my Palindrome program?
i = 0 h = 0 t = 0 p = '' z = 0
You can start by using mnemonic variable names. These ones make the
algorithm a chore to read. Feel free to re-post it when you've done so.
--
\ "I believe in making the world safe for our children, but not |
`\ our children's children, because I don't think children should |
_o__) be having sex." -- Jack Handey |
Ben Finney <http://bignose.squidly.org/>
Knowing what your program should do, could also help.
G-:
"Runic911" <ru******@aol.com> wrote in message news:20***************************@mb-m12.aol.com...
| Does anyone know how i can fix my Palindrome program?
|
| s = raw_input('Enter a String: ')
| punctuation = '%$!*.,-:? ;()\'\"\\'
| i = 0
| h = 0
| t = 0
| p = ''
| z = 0
| while s!= ' ':
| while i <= len(s) - 1:
| punct = s[i]
| if punctuation.find(punct) == -1:
| p = p + punct
| i = i + 1
| t = p.lower()
| t[h] == t[len(t)-1-h]
--
Georgy Pruss
E^mail: 'ZDAwMTEyMHQwMzMwQGhvdG1haWwuY29t\n'.decode('base6 4')
Georgy Pruss wrote: Knowing what your program should do, could also help. G-:
As far as I know is a palindrome a word that you can read from both
sides. Sorry, but English is not my native language. So I don´t have an
English example handy. But the German name 'OTTO' is a palindrome.
--
-- Ulli www.u-schramme.de
Hi Runic911,
You probably want this
t = p.lower()
t[h] == t[len(t)-1-h]
to do something. As it is now you don't report anything.
Looking at it some more I see it has several other problems.
The code starting at 't=p.lower()' needs to be dedented a
few levels so it is outside of the 'while s != '':' loop.
Also, that should be 'if s != '':' and likely doesn't
even need to be there at all.
In addition, you could shorten it by quite a bit by using
some of this higher-level functions available in Python.
Here's some pointers.
1) get rid of puncutation in one step rather than several.
You can use the re module for that, as in s = "A man, a plan, a canal -- Panama!" import re re.sub(r'[%$!*.,:? ;()\'\"\\-]', '', s)
'AmanaplanacanalPanama'
This is tricky, in part because the '-' must be at the end of pattern.
You could also use the translate function, as in
punctuation = '%$!*.,-:? ;()\'\"\\' identity = "".join([chr(i) for i in range(256)]) s.translate(identity, punctuation)
'AmanaplanacanalPanama'
This is also tricky because you have to use an identity
translation table. (On the other hand, done correctly this
could also convert everything to lower case.) I would
like a function which only removed a selected set of
characters.
Or you could make your own function for it
def remove_punctuation(s):
.... letters = []
.... for c in s:
.... if c not in punctuation:
.... letters.append(c)
.... return "".join(letters)
.... remove_punctuation(s)
'AmanaplanacanalPanama'
You could put this all into your palindrome code but
it's usually easier to understand your code if each
step does one thing. By the way, an experienced
Python programmer might write this function as
def remove_punctuation(s):
return "".join([c for c in s if c not in punctuation])
(since I didn't test this one, odds are good there's
a typo ;)
2) convert everything to the same case. If you use
the regular expression way then use the lower() method,
which you know about already.
The translate function can do it like this
for upper, lower in zip(string.ascii_uppercase, string.ascii_lowercase):
.... foldcase[ord(upper)] = lower
.... foldcase = "".join(foldcase) s
'A man, a plan, a canal -- Panama!' s.translate(foldcase, punctuation)
'amanaplanacanalpanama'
3) instead of comparing the string to itself, make a
new string which is a reverse of the old one and compare
the strings to each other
In newer Pythons (2.3) you can use [::-1] as a way
to slice the string backwards. Here's some examples
s
'A man, a plan, a canal -- Panama!' s[::-1]
'!amanaP -- lanac a ,nalp a ,nam A' t = s.translate(foldcase, punctuation) t
'amanaplanacanalpanama' t[::-1]
'amanaplanacanalpanama'
Since t == t[::-1] you know they are palindromes.
For older Pythons you'll need to turn the string
into a list of characters, reverse the list, and turn
it back into a string, as in
chars = list(s) chars
['A', ' ', 'm', 'a', 'n', ',', ' ', 'a', ' ', 'p', 'l', 'a', 'n', ',', ' ',
'a', ' ', 'c', 'a', 'n',
'a', 'l', ' ', '-', '-', ' ', 'P', 'a', 'n', 'a', 'm', 'a', '!'] chars.reverse() chars
['!', 'a', 'm', 'a', 'n', 'a', 'P', ' ', '-', '-', ' ', 'l', 'a', 'n', 'a',
'c', ' ', 'a', ' ', ',',
'n', 'a', 'l', 'p', ' ', 'a', ' ', ',', 'n', 'a', 'm', ' ', 'A'] "".join(chars)
'!amanaP -- lanac a ,nalp a ,nam A'
This should be enough information for you to make a
very nice palindrome function.
Andrew da***@dalkescientific.com
Runic911 wrote: Does anyone know how i can fix my Palindrome program?
s = raw_input('Enter a String: ') punctuation = '%$!*.,-:? ;()\'\"\\' i = 0 h = 0 t = 0 p = '' z = 0 while s!= ' ': while i <= len(s) - 1: punct = s[i] if punctuation.find(punct) == -1: p = p + punct i = i + 1 t = p.lower() t[h] == t[len(t)-1-h]
I´m not very experienced with Python but I think you could do it in a
more simple way.
inp = raw_input('Enter a string: ')
pal = []
rev = []
for c in inp:
if c.isalnum():
pal.append(c.upper())
rev.append(c.upper())
rev.reverse()
if pal == rev:
print '"' + inp + '" ' + 'is a palindrome.'
else:
print '"' + inp + '" ' + 'is no palindrome.'
--
-- Ulli www.u-schramme.de
Ulrich Schramme: I´m not very experienced with Python but I think you could do it in a more simple way.
Looks good to me. And it shows that I'm no longer able to help out
beginning programmers since my solution is along the lines of
inp = raw_input('Enter a string: ')
punctuation = '%$!*.,-:? ;()\'\"\\'
foldcase = [chr(i) for i in range(256)]
for upper, lower in zip(string.ascii_uppercase, string.ascii_lowercase):
foldcase[ord(upper)] = lower
foldcase = "".join(foldcase)
t = inp.translate(foldcase, punctuation)
if t != t[::-1]:
print '"' + inp + '" ' + 'is a palindrome.'
else:
print '"' + inp + '" ' + 'is not a palindrome.'
Faster, but with a startup cost and a high learning curve.
It's what I would use for my own code.
A slightly easier to understand and slower version is
inp = raw_input('Enter a string: ')
punctuation = '%$!*.,-:? ;()\'\"\\'
identity = "".join([chr(i) for i in range(256)])
t = inp.translate(identity, punctuation).lower()
if t != t[::-1]:
...
Yours is definitely easiest to understand so best for
the OP.
Cheers,
Andrew da***@dalkescientific.com
Andrew Dalke wrote: Ulrich Schramme:
I´m not very experienced with Python but I think you could do it in a more simple way.
Looks good to me. And it shows that I'm no longer able to help out beginning programmers since my solution is along the lines of
inp = raw_input('Enter a string: ')
punctuation = '%$!*.,-:? ;()\'\"\\' foldcase = [chr(i) for i in range(256)] for upper, lower in zip(string.ascii_uppercase, string.ascii_lowercase): foldcase[ord(upper)] = lower foldcase = "".join(foldcase)
t = inp.translate(foldcase, punctuation) if t != t[::-1]: print '"' + inp + '" ' + 'is a palindrome.' else: print '"' + inp + '" ' + 'is not a palindrome.'
Faster, but with a startup cost and a high learning curve. It's what I would use for my own code.
A slightly easier to understand and slower version is
inp = raw_input('Enter a string: ') punctuation = '%$!*.,-:? ;()\'\"\\' identity = "".join([chr(i) for i in range(256)])
t = inp.translate(identity, punctuation).lower() if t != t[::-1]: ...
Yours is definitely easiest to understand so best for the OP.
Cheers, Andrew da***@dalkescientific.com
Thanks Andrew,
there might be a million ways to solve the palindrome problem. I think
that another good way would be the use of regular expressions. I´m a
software developer by profession but quite new to Python. So I tried to
find an easy way that fits my limited knowledge of the Python syntax.
My first impression of Python is that it is a well - designed and
interesting language. I also like this newsgroup. People here seem to be
more helpful than in some other groups I know...
Hopefully taking part in discussions here will improve my English as
well as my Python :-)
--
-- Ulli www.u-schramme.de
"Ulrich Schramme" <ne**@u-schramme.de> wrote in message news:bo**********@online.de...
| Georgy Pruss wrote:
| > Knowing what your program should do, could also help.
| > G-:
| >
|
| As far as I know is a palindrome a word that you can read from both
| sides. Sorry, but English is not my native language. So I don´t have an
| English example handy. But the German name 'OTTO' is a palindrome.
I know what is a palindrome, but I can make up dozen things
the program could do with the palindrom.
G-:
|
|
| --
| -- Ulli
| www.u-schramme.de
|
Georgy Pruss wrote: I know what is a palindrome, but I can make up dozen things the program could do with the palindrom. G-:
Sorry, it seems that I misunderstood your previous posting.
--
-- Ulli www.u-schramme.de
Georgy Pruss wrote: I know what is a palindrome, but I can make up dozen things the program could do with the palindrom. G-:
I´m sorry, but it seems that I misunderstood your previous posting.
--
-- Ulli www.u-schramme.de
[Ulrich Schramme] there might be a million ways to solve the palindrome problem. I think that another good way would be the use of regular expressions.
The same occurred to me, so I had a go. This is as well as I was able
to do in my lunchtime.
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
import re
ignore = """ ",.'`!?-"""
def isPalindrome(s):
testphrase = re.sub("[%s]" % ignore, '', s)
numtomatch = len(testphrase)/2
regx = "(\S)?"
for x in range(numtomatch):
regx = "(\S)%s(\%d)" % (regx, numtomatch-x)
rxc = re.compile(regx, re.I)
result = rxc.match(testphrase)
return result is not None
phrases = [
"Able was I, `ere I saw Elba",
"A man, a plan, a canal, Panama",
"Go Hang a Salami! I'm a Lasagna Hog!",
"Sit on a Potato Pan, Otis",
"Too Hot to Hoot",
"If I Had a Hi-Fi",
"So Many Dynamos",
"Madam I'm Alan",
"Santa, Oscillate My Metallic Sonatas",
"Knob, testes set? Set. Bonk!",
]
if __name__ == "__main__":
print "Palindromes:"
for phrase in phrases:
if isPalindrome(phrase):
print "Yes: '%s'" % phrase
else:
print "No : '%s'" % phrase
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
I'm not too happy with it though. There must be some way to have a
single fixed regular expression that can be used to test every
palindrome.
regards,
--
alan kennedy
-----------------------------------------------------
check http headers here: http://xhaus.com/headers
email alan: http://xhaus.com/mailto/alan
Runic911 wrote: Does anyone know how i can fix my Palindrome program?
A palindrome program?
Are you looking for:
20:58:42:232:0 >>> def ispalindrome(s):
20:58:42:232:0 ... return s == s[::-1]
20:58:42:232:0 ...
20:58:57:232:1 >>> ispalindrome("bolton")
False
20:59:15:232:3 >>> ispalindrome("mooiezepeninepezeioom")
True
20:59:27:232:4 >>> ispalindrome("")
True
?
yours,
Gerrit.
--
276. If he hire a freight-boat, he shall pay two and one-half gerahs
per day.
-- 1780 BC, Hammurabi, Code of Law
--
Asperger Syndroom - een persoonlijke benadering: http://people.nl.linux.org/~gerrit/
Kom in verzet tegen dit kabinet: http://www.sp.nl/
Alan Kennedy: I'm not too happy with it though. There must be some way to have a single fixed regular expression that can be used to test every palindrome.
There isn't such a way. Regular expressions cannot match
strings of the form a**n b**n a**n (pumping lemma). That's
a palindrome so there are palindromes which cannot be
matched by regular expressions.
There are tricks. "regular expressions" aren't actually regular
and can be used to match things like a**n b**m a**n (because
of the \1 feature). However, there still isn't enough to match
a palindrome of arbitrary length. (It would be trivial to add such
a feature -- let \~1 match the reverse of the first match then
^(.*).?\~1$
would match all palindromes... slowly. But no such feature
exists in any regexp engine I know of.)
Andrew da***@dalkescientific.com
Gerrit Holl Are you looking for: 20:58:42:232:0 >>> def ispalindrome(s): 20:58:42:232:0 ... return s == s[::-1]
No. The OP wanted to strip special characters and
normalize case, so that
A man, a plan, a canal -- Panama!
would be allowed as a palindrome.
Andrew da***@dalkescientific.com
On Thu, 13 Nov 2003 23:16:50 GMT, Andrew Dalke wrote: Gerrit Holl Are you looking for: 20:58:42:232:0 >>> def ispalindrome(s): 20:58:42:232:0 ... return s == s[::-1]
No. The OP wanted to strip special characters and normalize case, so that A man, a plan, a canal -- Panama! would be allowed as a palindrome.
Here's mine.
I have yet to try this on the world's longest palindrome:
<http://www.norvig.com/palindrome.html>
=====
#!/usr/bin/env python
""" Module for palindrome determination
"""
import string
def is_palindrome( str ):
""" Determine if str is a palindrome
"""
# Assume false until proven otherwise
is_pal = False
# Remove punctuation and whitespace
passthrough_tbl = string.maketrans( '', '' )
remove_chars = string.whitespace + string.punctuation
str = string.translate( str, passthrough_tbl, remove_chars )
# Remove capitalisation
str = string.lower( str )
# Determine if massaged string matches its reverse
is_pal = ( str == str[::-1] )
return is_pal
if( __name__ == '__main__' ):
candidates = [
"",
"Foo",
"FooF",
"Foof",
"Foxof",
"Madam, I'm Adam.",
"Ten animals I slam in a net.",
"Lapses? Order red roses, pal.",
"A man, a plan, a canal -- Panama!",
"Satan, oscillate my metallic sonatas.",
"Eva, can I stack Rod's sad-ass, dork cats in a cave?",
]
for str in candidates:
print ( "'%s':" % str ),
print is_palindrome( str )
=====
--
\ "I wish I had a dollar for every time I spent a dollar, because |
`\ then, yahoo!, I'd have all my money back." -- Jack Handey |
_o__) |
Ben Finney <http://bignose.squidly.org/>
Ben Finney wrote: I have yet to try this on the world's longest palindrome:
<http://www.norvig.com/palindrome.html>
is_pal = ( str == str[::-1] )
For really long palindromes, you might not want to reverse the whole string:
p.endswith(p[:len(p)//2:-1])
Peter
[Alan Kennedy] ... There must be some way to have a single fixed regular expression that can be used to test every palindrome.
[Andrew Dalke] There isn't such a way. Regular expressions cannot match strings of the form a**n b**n a**n (pumping lemma). That's a palindrome so there are palindromes which cannot be matched by regular expressions.
Thanks Andrew.
I read up on the topic after posting yesterday (because I had this
vague niggling doubt). After finding that what you stated above is
true, I realised that the vague niggling doubt was actually the memory
of my old compiler-theory lecturer laughing at me :-D
Here's a nice page I found that discusses this and other related
topics.
FINITE STATE AUTOMATA AND REGULAR EXPRESSIONS http://www.cs.princeton.edu/introcs/71regular/
There are tricks. "regular expressions" aren't actually regular and can be used to match things like a**n b**m a**n (because of the \1 feature). However, there still isn't enough to match a palindrome of arbitrary length. (It would be trivial to add such a feature -- let \~1 match the reverse of the first match then ^(.*).?\~1$ would match all palindromes... slowly. But no such feature exists in any regexp engine I know of.)
The possibility of the same feature occurred to me. However, I'm still
not sure if this would solve the problem. How would the "pivot point"
be recognised by such an augmented regex engine? i.e. how would it
recognise the point at which it should stop capturing, reverse the
sequence and start matching again?
Perhaps one would need to also implement a feature whereby the length
of the entire string could be made available within expressions, so
that the size of a capture group could be limited to the first half of
the string? I.E. Something along the lines of
^(.{strlen/2}).?\~1$
One of these days I'll find the time to dig out my old course notes
and books :#)
regards,
--
alan kennedy
-----------------------------------------------------
check http headers here: http://xhaus.com/headers
email alan: http://xhaus.com/mailto/alan
On Thu, 13 Nov 2003 17:32:06 +0000, Alan Kennedy <al****@hotmail.com>
wrote: I'm not too happy with it though. There must be some way to have a single fixed regular expression that can be used to test every palindrome.
regards,
Thought I'd give it a try too. This is what I came up with. I used
the regular expression re.sub() function to remove the punctuation and
spaces.
The really hard part was trying to come up with a palindrome that has
the word python in it. :-)
_Ron Adam
"""
Test if a string is a palindrome.
"""
import re
def palindrome_test(p):
p = p.lower()
p = re.sub(r'\W','',p)
while p:
if p[:1] == p[-1:]:
p = p[1:-1]
else:
break
if (len(p) <= 1):
return True
else:
return False
palindrome_list = ["Bolton",
"No 'H' type, mate. No spot stops one tame
python!",
"A man, a plan, a cat, a ham, a yak, a yam, a hat,
a canal--Panama!",
"Was it a car or a cat I saw?",
"This is not a palindrome!"]
for p in palindrome_list:
print '"'+p+'"',
if palindrome_test(p):
print 'is a palindrome.'
else:
print 'is not a palindrome.'
On Fri, 14 Nov 2003 11:51:02 GMT, Ron Adam <ra****@tampabay.rr.com>
wrote: """ Test if a string is a palindrome. """ import re
def palindrome_test(p): p = p.lower() p = re.sub(r'\W','',p) while p: if p[:1] == p[-1:]: p = p[1:-1] else: break if (len(p) <= 1): return True else: return False
I notice right after I posted it, I can simplify the test function a
bit more.
import re
def palindrome_test(p):
p = p.lower()
p = re.sub(r'\W','',p)
while p and p[:1] == p[-1:]:
p = p[1:-1]
return (len(p) <= 1)
_Ron Adam
Ron Adam wrote: I notice right after I posted it, I can simplify the test function a bit more.
import re def palindrome_test(p): p = p.lower() p = re.sub(r'\W','',p) while p and p[:1] == p[-1:]: p = p[1:-1] return (len(p) <= 1)
Ron,
If I were going to follow this approach, I would try to eliminate any
copying, like so:
def palindrome_test(p):
p = p.lower()
p = re.sub(r'\W','',p)
plen = len(p)
for i in xrange(plen/2):
if p[i] != p[plen-i-1]:
return False
return True
regards,
--
alan kennedy
-----------------------------------------------------
check http headers here: http://xhaus.com/headers
email alan: http://xhaus.com/mailto/alan
Andrew> Gerrit Holl Are you looking for: 20:58:42:232:0 >>> def ispalindrome(s): 20:58:42:232:0 ... return s == s[::-1]
Andrew> No. The OP wanted to strip special characters and
Andrew> normalize case, so that
Andrew> A man, a plan, a canal -- Panama!
Andrew> would be allowed as a palindrome.
Oh, then how about :
import re
def ispalindrome(s):
s = re.sub("[^A-Za-z0-9]+", "", s).lower()
return s == s[::-1]
for s in (
"A man, a plan, a canal -- Panama!",
"1234",
"123321",
"Madam, I'm Adam."):
print s, "->", ispalindrome(s)
Skip
On Fri, 14 Nov 2003 14:34:23 +0000, Alan Kennedy <al****@hotmail.com>
wrote: If I were going to follow this approach, I would try to eliminate any copying, like so:
def palindrome_test(p): p = p.lower() p = re.sub(r'\W','',p) plen = len(p) for i in xrange(plen/2): if p[i] != p[plen-i-1]: return False return True
regards,
Good point. Ok, how about like this?
"""
Test if a string is a palindrome.
"""
import re
def palindrome_test(p):
p = re.sub(r'\W','',p.lower())
i = len(p)//2
while i and p[i] == p[-i-1]: i -= 1
return not i
palindrome_list = [
"A",
"ab",
"Oo!",
"Bolton",
"This is not a palindrome!",
"Was it a car or a cat I saw?",
"No 'H' type, mate, no spot stops one tame python!",
"A man, a plan, a cat, a ham, a yak, a yam, a hat, a
canal--Panama!",
]
for p in palindrome_list:
print '"'+p+'"',
if palindrome_test(p):
print 'is a palindrome.'
else:
print 'is not a palindrome.'
Alan Kennedy The possibility of the same feature occurred to me. However, I'm still not sure if this would solve the problem. How would the "pivot point" be recognised by such an augmented regex engine? i.e. how would it recognise the point at which it should stop capturing, reverse the sequence and start matching again?
Back-tracking. Suppose there was such a thing as
(.*).?\~1
where the \~1 matches the reverse of the first group.
Now match that pattern against
NOON
The (.*) matches all the way up to "NOON" then tries and
failes to match both the .? and the \~1
It backtracks one so that
(.*) matches "NOO"
and the N remains. The .? matches the N but the \~1 does not
so it backtracks so that the .? matches nothing, but still the \~1
does not match the N.
It backtracks another so that
(.*) matches "NO"
and the "ON" remains. The .? first matches with the "O" leaving
the "N", but \~1 doesn't match that, so it backtracks so that
the .? matchs nothing, leaving "ON" for the \~1. This matches!
In other words, it goes through a lot of work to do the matching,
and would take O(N) backtracks to work.
But that's not quite correct. An implementation is free to
analyze the pattern and notice that it's being asked to search
for a palindrome then insert special case code for that pattern.
Perhaps one would need to also implement a feature whereby the length of the entire string could be made available within expressions, so that the size of a capture group could be limited to the first half of the string? I.E. Something along the lines of
^(.{strlen/2}).?\~1$
Yup. That would work as well. There are all sorts of
special things one could capture in a regex-like language.
Perl 'solves' it by allowing any match to call out to embedded
Perl code, which is free to tell the matcher to stop or
continue matching.
One of these days I'll find the time to dig out my old course notes and books :#)
Friedl's regexp book (from ORA) is quite good.
Andrew da***@dalkescientific.com
Skip: Oh, then how about:
...
At the end are the three solutions I saw posted, from Ron Adam,
Skip, and me (modified). The times are
palindrome_adam 128.152670758
palindrome_skip 89.5211577111
palindrome_dalke 11.1900866758
Andrew da***@dalkescientific.com
import re, timeit
# from Ron Adam
def palindrome_adam(p):
p = re.sub(r'\W','',p.lower())
i = len(p)//2
while i and p[i] == p[-i-1]: i -= 1
return not i
# from Skip Montanaro
def palindrome_skip(s):
s = re.sub("[^A-Za-z0-9]+", "", s).lower()
return s == s[::-1]
# from Andrew Dalke
foldcase = []
punctuation = []
for i in range(256):
c = chr(i)
if c.isalnum(): # note 'alnum' instead of 'alpha' ...
foldcase.append(c.lower())
else:
foldcase.append(c)
punctuation.append(c)
foldcase = "".join(foldcase)
punctuation = "".join(punctuation)
del c, i
def palindrome_dalke(s):
t = s.translate(foldcase, punctuation)
return t == t[::-1]
verify_data = [
("A man, a plan, a canal -- Panama!", True),
("1234", False),
("123321", True),
("12321", True),
("Madam, I'm Adam.", True),
("A", True),
("ab", False),
("Oo!", True),
("Bolton", False),
("This is not a palindrome!", False),
("Was it a car or a cat I saw?", True),
("No 'H' type, mate, no spot stops one tame python!", True),
("A man, a plan, a cat, a ham, a yak, a yam, a hat, a canal--Panama!",
True),
]
def verify():
for tester in (palindrome_adam, palindrome_skip,
palindrome_dalke):
for s, result in verify_data:
assert tester(s) == result, (tester, s)
print "Verified"
_time_val = None
def find_times():
global _time_val
_time_val = verify_data[-1][0] # the long "a man, a plan ... Panama"
one
for tester in ("palindrome_adam", "palindrome_skip",
"palindrome_dalke"):
timer = timeit.Timer(setup = "import __main__ as M",
stmt = "M." + tester + "(M._time_val)")
t = timer.timeit()
print tester, t
if __name__ == "__main__":
verify()
find_times() This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Lorin Leone |
last post by:
Can anyone help me modify the program so that it recognizes strings
like "Anna" as palindromes. To make the program "case-insensitive."
using the built-in C++ function "toupper". and so that it...
|
by: Amar Prakash Tripaithi |
last post by:
Dan Hoey, who had recently graduated, wrote a C program to look for and
construct the following beauty:
A man, a plan, a caret, a ban, a myriad, a sum, a lac, a liar, a hoop,
a pint, a catalpa,...
|
by: ramakrishnadeepak |
last post by:
HI Everybody,
I 've to submit a program on c.Can any one help me
plz.........The problem is like this::
Write a program which computes the largest palindrome substring of a
string.
Input:...
|
by: outofmymind |
last post by:
hi,
im trying to solve the following question:
Create a class responsible for determining whether a string is a palindrome. Show your test cases. Palindome mypal("bob");
...
|
by: colinNeedsJavaHelp |
last post by:
I am still having an exceptional amount of trouble with java. This is my new assignment, if anyone can help I would greatly appreciate it. I don't even know where to start.
A word or phrase in...
|
by: Synapse |
last post by:
aloha people! I need help in my java palindrome program. It's a 5-digit palindrome checker. The code below is running good but i got a few problems on it.
If I enter 33633, 11211, 45554, it will...
|
by: Wabz |
last post by:
Hello mates,
Does anyone know how to write a function that tests if an integer is a
palindrome in C language?
|
by: vicestner |
last post by:
Write a Java program that prints the longest palindrome in an input file to standard output. A palindrome is a string whose reverse is the same as the original. Ignore case, whitespace, and...
|
by: rubyhuang |
last post by:
i'm a new perl learner, this is the first perl task i will do. please help me.
The user can input a string, and then a script will check to see if the string is a palindrome or not, displaying the...
|
by: bigtd08 |
last post by:
help writing this palindrome program for my c++ class.
HERE WHAT THE CODE SHOULD BE LIKE.
Write a program that takes a line of input from the keyboard and check to see if that line is a palindrome....
|
by: Kemmylinns12 |
last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
|
by: antdb |
last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine
In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
|
by: Arjunsri |
last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and credentials and received a successful connection...
|
by: WisdomUfot |
last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
|
by: Matthew3360 |
last post by:
Hi,
I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
|
by: Oralloy |
last post by:
Hello Folks,
I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA.
My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
|
by: BLUEPANDA |
last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
|
by: Rahul1995seven |
last post by:
Introduction:
In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
|
by: Johno34 |
last post by:
I have this click event on my form. It speaks to a Datasheet Subform
Private Sub Command260_Click()
Dim r As DAO.Recordset
Set r = Form_frmABCD.Form.RecordsetClone
r.MoveFirst
Do
If...
| |