[Tutor] How to find reverse pair words in a list of Words that has to be accessed through a URL
Chetan Sai
chetansaip at gmail.com
Fri Apr 19 23:19:10 CEST 2013
Hi Don
I'm a beginner in Python Programming.
I'm using python 3. I wrote a program that checks whether given two words
are reverse pair or not and outputs TRUE/FALSE.
*def reverse_pair(a,b):*
* return list(a)==list(reversed(list(b)))*
*
*
*
*
But how to write a program that finds all the reverse pairs in the given
word list, eg: how to find the reverse pair words in a list of 20 words.
And that to how to access those list of words form a URL.
Because with the above code we can only find out whether the given 2 words
are reverse pair or not, that's it.
I'm thinking of using the below code which is written for Python 2.7.
Code:
def reverse_pair(word_list, word):
"""Checks whether a reversed word appears in word_list.
word_list: list of strings
word: string
"""
rev_word = word[::-1]
return in_bisect(word_list, rev_word)
if __name__ == '__main__':
word_list = make_word_list()
for word in word_list:
if reverse_pair(word_list, word): print word, word[::-1]
On Fri, Apr 19, 2013 at 2:05 PM, Don Jennings <dfjennings at gmail.com> wrote:
>
> On Apr 19, 2013, at 4:56 PM, Chetan Sai wrote:
>
> > Here is my question:
> >
> > "Two words are a “reverse pair” if each is the reverse of the other.
> Write a program that finds all the reverse pairs in the word list. The word
> list can be downloaded athttp://www.puzzlers.org/pub/wordlists/pocket.txt"
>
> Really, that's not a question, but we are happy to answer questions :>)
> Oh, there's your question in the subject line. What have you tried thus
> far? Have you given any thought to what steps you might have to take to
> solve this task?
>
> Take care,
> Don
>
>
--
Thanks & Regards
Sai Chetan Pothula
408-203-3323
On Fri, Apr 19, 2013 at 2:05 PM, Don Jennings <dfjennings at gmail.com> wrote:
>
> On Apr 19, 2013, at 4:56 PM, Chetan Sai wrote:
>
> > Here is my question:
> >
> > "Two words are a “reverse pair” if each is the reverse of the other.
> Write a program that finds all the reverse pairs in the word list. The word
> list can be downloaded athttp://www.puzzlers.org/pub/wordlists/pocket.txt"
>
> Really, that's not a question, but we are happy to answer questions :>)
> Oh, there's your question in the subject line. What have you tried thus
> far? Have you given any thought to what steps you might have to take to
> solve this task?
>
> Take care,
> Don
>
>
--
Thanks & Regards
Sai Chetan Pothula
408-203-3323
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20130419/3b6e67df/attachment-0001.html>
More information about the Tutor
mailing list