[Tutor] Finding palindromes in a list
mnickey at gmail.com
Sat Jun 9 03:46:57 CEST 2012
Those have helped. Now a new issue comes up. The list 'palindrome' is
not being populated. I know that there is a few in the list. I think
this is in the compareElements def. While I'm familiar with the
.append() call I don't know why it's not populating the palindrome
Thanks again for all the assistance.
fname = raw_input('Enter location and filename: ')
#attempt the open the file for reading
fobj = open(fname, 'r')
except IOError, e:
print "*** file open error:", e
#display contents to the screen
for eachLine in fobj:
# create list here
for item in wordList:
if item == item[::-1]: #wordList[item] ==
wordList = 
palindromes = 
print "\nPrinting new Word list!!!"
print "\nComparing Word List!!!"
print "\nPrinting palindromes"
On Fri, Jun 8, 2012 at 6:38 PM, Dave Angel <d at davea.name> wrote:
> On 06/08/2012 09:01 PM, Marc Tompkins wrote:
>> On Fri, Jun 8, 2012 at 5:10 PM, Mike Nickey <mnickey at gmail.com> wrote:
>>> def compareElements(wordList):
>>> for item in wordList():
>>> if item == item.reversed():
>>> print item
>> reversed() is not a string method. To reverse a string, try something like
>>> if item == item[::-1]
> Also next(item) is useless and probably an error. You do not need an
> else clause there. the for loop takes care of those details.
More information about the Tutor