[Tutor] How to find reverse pair words in a list of Words that has to be accessed through a URL
emile
emile at fenx.com
Sat Apr 20 00:16:52 CEST 2013
On 04/19/2013 03:07 PM, Alan Gauld wrote:
> On 19/04/13 22:19, Chetan Sai wrote:
>
>> I'm a beginner in Python Programming.
>
> The language isn't really the issue here the issue is the algorithm.
> So how would you do it manually with a paper and pen? (forget about
> fetching the list from the URL for now)
>
> One possibility is to use sets (Python has a set data type).
> create a set of words.
> Now create a set of reversed words.
> The intersection of those sets is the set of words which
> also have a reversed pair.
>
> print the intersection set.
The gotcha with this approach is the border case of self paired words
that aren't pairs. (pop,wow,mom,etc)
I got 94 distinct pairs. Which is a better result than the 124.5 pairs
I got the first pass through.
Emile
More information about the Tutor
mailing list