Pairpal

Find pairs of words which form palindromes and write to standard output
import sys file = open("words.txt","r") words = file.read data = words.split("\n") for y in data: for x in data: z = "".join([y,x]) w = z[:][::-1] if w == z:            v = "".join([y," ",x]) sys.stdout.write('\n'+v)
 * 1) !/usr/bin/python

@linuxgal Quadratic? .5s runtime. #python

import sys file = open("words.txt","r") words = file.read data = [d for d in words.split("\n") if not d.strip == ''] d1 = sorted(data) d2 = sorted([d[::-1] for d in data]) i = 0 j = 0 done = False while i	< len(d1) and j	< len(d2): if d1[i] < d2[j]: i += 1 elif d1[i] > d2[j]: j += 1 else: print(d1[i], d2[j][::-1]) i += 1 j += 1
 * 1) !/usr/bin/python



abe reba / able elba / able melba / abler elba / accede decca / ada cicada / ada dada / adana canada / ado coda / ado soda / ado yoda / agar raga / age sega / age vega / ages sega / aglow olga / ago toga / aide media / ailed delia / aimed academia / aimee mia / airy syria / ale vela / align gila / alley ella / allude medulla / along nola / amen enema / ammo momma / amoral aroma / anal lana / anita latina / anita patina / anita tina / ante etna / apse spa / ares era / arid ira / arises ira / aroma zamora / attests etta / avid diva / avon nova / avon ova / avow ova / babe kebab / bach cab / back cab / bah ahab / bald lab / bale lab / bali lab / balk lab / ball lab / balm lab / balsa slab / banana nab / band nab / bank nab / bar crab / bar drab / bard drab / bath tab / bats stab / bats tab / bed deb / bilge glib / birch crib / bog gob / bolt lob / bomb mob / booby boob / bordered rob / bore rob / borg rob / bork rob / born rob / bosh sob / bosses sob / bra barb / bra garb / brags garb / bruce curb / buck cub / bud dub / bun nub / bun snub / bung nub / bunk nub / buns nub / buns snub / burdened rub / burg grub / burg rub / burgs grub / burn rub / burr rub / bursitis rub / bursts rub / burt rub / butt tub / camus sumac / cassettes sac / cassia issac / cigar tragic / cite mimetic / cite tic / city tic / colby bloc / crab arc / cram arc / crap arc / crass arc / craw arc / cray arc / crop orc / cross orc / crow orc / dale lad / damon nomad / darby brad / dash sad / data tad / date tad / dawn wad / deb bobbed / debora robed / debra barbed / debra garbed / debut tubed / decal aced / decal laced / decal placed / decals laced / decamp maced / decay aced / decided iced / deena need / deep peed / deer creed / deer freed / deer greed / deer treed / deity tied / delete led / deli ailed / deli assailed / deli availed / deli filed / deli led / deli oiled / deli piled / deli riled / deli tiled / deli wiled / delia ailed / delia failed / delia hailed / delia jailed / delia mailed / delia nailed / delia railed / delia sailed / delia wailed / deliver reviled / delivers reviled / dell appalled / dell led / della balled / della called / della galled / della palled / della totalled / della walled / demanded named / demo domed / demo homed / dena caned / dena waned / denier reined / deniers reined / denote toned / depart raped / derby bred / detract carted / deuce cued / dew awed / dew owed / dew wed / dewar awed / dewy wed / dial aid / dial laid / dial plaid / dials laid / diann aid / diaper prepaid / diaper repaid / diary raid / dido did / dike kid / dill lid / dim amid / dim mid / dime mid / dims mid / din enid / dirge grid / dirk rid / dirt rid / diva avid / diva david / divan avid / divot ovid / dog god / dogs god / don nod / dona nod / done nod / dons nod / dooms mood / door brood / door rood / doors rood / dope pod / dork rod / dorm rod / dory rod / drab bard / drabs bard / draco card / drags asgard / draw award / draw ward / drawer reward / drawers reward / drawl ward / drawn inward / drawn onward / drawn ward / draws ward / dray yard / drays yard / drowse sword / drowsy sword / dual laud / dub bud / dubs bud / duck cud / duct cud / due feud / duh thud / duo loud / dwell lewd / dwelt lewd / ebay abe / edam made / edith tide / edits tide / eel flee / eel lee / eire aerie / eire eerie / eire erie / elapses pale / elate tale / elba able / elba cable / elba fable / elba gable / elba mable / elba table / elite tile / elope pole / elsie isle / emacs came / emil clime / emil lime / emil slime / emile lime / emily lime / emir crime / emir grime / emit noontime / emit time / emits time / emote tome / emu fume / emu hume / enact cane / enoch cone / era care / era fare / era hare / era mare / era pare / era rare / era tare / ergo ogre / eric ire / erie eire / erie ire / erik ire / erin ire / eroded ore / errol lorre / erupt pure / eta bate / eta collocate / etna ante / etta latte / etta matte / euro rue / eva cave / eva dave / eva eave / eva gave / eva have / eva nave / eva pave / eva rave / eva save / eva wave / evade dave / evan knave / evan nave / evans nave / even eve / ever eve / eves eve / evian naive / evil alive / evil clive / evil live / evil olive / eviler relive / evils live / evita dative / evita native / eyed eye / eyes eye / flack calf / flesh self / flog golf / flogs golf / flow wolf / flown wolf / flows wolf / flu gulf / fool aloof / fresh serf / gabs bag / gaff fag / gage gag / gags gag / gal flag / gal lag / gal slag / gala lag / gale lag / gals lag / gals slag / gang nag / garb rag / gardened rag / gary rag / gas sag / gash sag / gasp sag / gasses sag / gate tag / gawk wag / gel leg / geld leg / gelded leg / gels leg / gelt leg / gem meg / gemini meg / gems meg / gibe big / gide dig / gift fig / gigolo gig / gigs gig / gird rig / girded rig / girl rig / girt rig / girt trig / gnat tang / gnats tang / gnaw twang / gnaw wang / gnawn wang / gnaws wang / gnu bung / gnu dung / gnu hung / gnu lung / gnu rung / gnu sung / gnus sung / gob bog / gobi bog / gobs bog / god dog / gods dog / gog agog / golf flog / golf log / gorge grog / greece erg / grew erg / grey erg / grub burg / grubs burg / gulp plug / gulps plug / gum smug / guru rug / gut tug / guts tug / hair uriah / hall allah / harass sarah / harasses sarah / harp oprah / hoops pooh / kay yak / keel leek / keel sleek / keels leek / keels sleek / keep peek / knife fink / knit ink / knock conk / kooks kook / kooky kook / kris irk / kroc cork / lace decal / lace fecal / laced decal / lag gal / lagers regal / lags gal / laid dial / lair trial / lama jamal / lana anal / lana banal / lana canal / lanai anal / lane penal / lane renal / lane venal / lap opal / lap pal / laps pal / lapses pal / lash sal / lass sal / lasses sal / lassos sal / last sal / late fetal / late petal / laud dual / lauds dual / lava laval / lebanon abel / lee eel / lee feel / lee keel / lee peel / lee reel / leek eel / leek keel / leer creel / leer eel / leer reel / leers reel / leery reel / lees eel / leg gel / lego gel / legs gel / lei kiel / lei riel / lena panel / leo joel / leo noel / leon noel / leona noel / lepers repel / levant navel / levels level / lever revel / levers revel / liar ail / liar frail / liar grail / liar rail / liar trail / liars rail / lice cecil / lie neil / lien neil / liens neil / lima mil / lima tamil / limb mil / lime emil / lime mil / limed emil / limes emil / limn mil / limo mil / limp mil / line nil / lint nil / lion oil / lire peril / live devil / live evil / liven evil / liver evil / lives evil / llama mall / lonely tylenol / loop pool / loop spool / loops pool / loops spool / loot stool / loot tool / looter retool / looters retool / lop pol / lope pol / lops pol / lorn enrol / lorre errol / lose sol / loss sol / losses sol / lost sol / lyra daryl / made dam / made edam / mads dam / mae ream / mae seam / mae team / male lam / man nam / manama nam / mann annam / mann nam / manna annam / manses nam / manx nam / many nam / mao loam / map pam / maps pam / mar cram / mar dram / mar gram / mar pram / mar ram / mar tram / maraca ram / marco cram / marcy cram / mare ram / marge gram / mark ram / mars ram / mart ram / mart tram / marta tram / martini tram / marts tram / marty tram / marx ram / mary ram / maw swam / max exam / maxed exam / maxes exam / may yam / maya yam / mayo yam / mays yam / meet teem / meg gem / megs gem / mel clem / mia aim / mia maim / mid dim / mike kim / mil slim / mile selim / miles selim / mils slim / minima minim / minims minim / mira rim / mira tarim / mire rim / mirror rim / mirth trim / misdeed sim / misdid sim / misses sim / mist sim / mit tim / mite tim / mitt tim / moms mom / moo boom / moo loom / moo room / moo zoom / moor broom / moor groom / moor room / moors room / mote tom / moth tom / mott tom / motto bottom / murdered rum / murk rum / muse sum / mush sum / musk sum / muss opossum / muss sum / musses sum / mutate tatum / nab ban / nabs ban / nail ian / nail lillian / naive evian / name man / nanette nan / naomi moan / nap pan / nap span / nape pan / naps pan / naps span / nat stan / nat tan / nate tan / nature rutan / nave evan / nave van / navel evan / naves evan / navy van / nay ryan / ned den / ned eden / neil alien / neil lien / nell allen / nell ellen / nell len / nerf efren / nero goren / nero loren / net ten / never even / new gwen / new wen / niagara gain / nib bin / nib bobbin / nigh gin / nil olin / nil poplin / nine benin / nine lenin / nip pin / nip spin / nita latin / nita satin / nita tin / nite tin / niter cretin / nits tin / nod don / nodded don / node don / nods don / noel eon / noel leon / noels leon / noes eon / noise lesion / noises ion / nola halon / nola salon / nomad damon / nomads damon / nome demon / nome lemon / non anon / nona anon / nona canon / nona non / none non / none xenon / noose soon / nor aaron / nor aron / nor iron / nor ron / nora aaron / nora aron / nora baron / nora ron / norad aron / norm ron / nose son / nosh son / nosy dyson / nosy son / nosy tyson / not eton / not ton / note eton / note seton / note ton / noted eton / notes eton / notes seton / nova avon / novae avon / novas avon / now won / nub bun / nubs bun / nuns nun / nurses run / nut stun / nut tun / nuts stun / nuts tun / oat tao / oath tao / oats tao / obit ibo / ode redo / oder credo / oder redo / ogre ergo / ogres ergo / ohsa basho / oil clio / olson oslo / ooze zoo / orb ebro / ore cicero / ore hero / ore nero / ore zero / otis ito / otto motto / pace cap / pace recap / pack cap / pact cap / page gap / pal clap / pal flap / pal lap / pal slap / pale lap / palette lap / pall lap / palm lap / pals lap / pals slap / palsy slap / pam map / pan nap / pan snap / panama nap / pane nap / pans nap / pans snap / pant nap / papa pap / paps pap / par crap / par rap / par trap / parch crap / pare rap / parses rap / part rap / part strap / part trap / partner entrap / parts strap / parts trap / party trap / pat tap / pate tap / path tap / pats tap / paw swap / paws swap / pay yap / payee yap / pays yap / peed deep / peek keep / peel bleep / peel sleep / peels asleep / peels sleep / peeps peep / pees seep / peeve veep / peewee weep / per prep / per rep / perk rep / perl rep / perm rep / pert rep / pert strep / peru rep / pike kip / pile lip / pill lip / pin nip / pin snip / pine nip / ping nip / pink nip / pins nip / pins snip / pint nip / pipe pip / pis sip / pisa sip / piss sip / pisses sip / pit tip / pita tip / pith tip / pits tip / pitt tip / pity tip / plug gulp / plugs gulp / pocono cop / pole lop / polk lop / poll lop / polo lop / pols lop / pols slop / pooch coop / pool loop / pool sloop / poole loop / pools loop / pools sloop / poops poop / poor droop / poor troop / pope pop / pops pop / porch crop / port strop / ports strop / pose aesop / pose sop / posh sop / posses sop / possesses sop / post sop / posy sop / pot atop / pot stop / pot top / pots nonstop / pots stop / pots top / prawn warp / pupa pup / pups pup / purism sirup / race car / raceme car / racy car / radar adar / radars radar / raft far / rag agar / raga agar / raga hagar / ragas agar / rail liar / rails liar / raja jar / ram omar / ramon omar / rap par / rap spar / rape par / raps par / raps spar / rapt par / rasta tsar / rat avatar / rat star / rat tar / rate tar / rats star / rats tar / raw war / reba haber / reba saber / rebut tuber / rebuts tuber / recluses ulcer / red oder / redness sender / redo oder / redraw warder / redrawn warder / redraws warder / reeds deer / reedy deer / reel leer / reels leer / reeve veer / refer prefer / refile lifer / refill lifer / refine jenifer / regina niger / regor kroger / reined denier / relive eviler / relive reviler / relive viler / relived eviler / relives eviler / rena saner / renee keener / reno boner / reno goner / reno loner / reno toner / repaid diaper / resale laser / resold loser / retool looter / retools looter / retract carter / revel clever / revel ever / revel lever / revels lever / revile deliver / revile liver / reviled deliver / revolt lover / reward drawer / rewards drawer / reword rower / reworded rower / rework rower / rio memoir / rise sir / risk sir / rod odor / roman enamor / room moor / rooms moor / rot tor / rote tor / roth tor / rotors rotor / rots astor / rots tor / rover trevor / rub bur / rube bur / rubs bur / ruby bur / rum amur / sade vedas / sag gas / saga gas / saga ragas / sage gas / sage vegas / sagging niggas / sags gas / salad alas / salas alas / sale las / salish silas / salk las / salsas las / salt atlas / salt las / same mas / sameness enemas / saner arenas / saps pas / saps spas / sate betas / satin unitas / saw was / sawn was / saws was / scam emacs / scram arcs / scrap arcs / scroll orcs / see fees / see gees / see lees / see pees / see referees / see sees / see tees / see wees / seep pees / seer frees / seer trees / seine denies / seine genies / semite times / senile felines / senile lines / sepal apes / serape pares / seraph pares / seton notes / seuss issues / seuss sues / sever eves / severer eves / sew awes / sew ewes / sew owes / sewer ewes / sex axes / sex exes / sexed exes / sexes exes / sexing nixes / sexism sixes / sexist sixes / side dis / sill ellis / silo solis / sine penis / sip pis / sips pis / sir gris / sir kris / sir uris / sis isis / sit otis / sitar gratis / siva avis / siva davis / siva mavis / six axis / slag gals / slags gals / slam mammals / slap opals / slap pals / slaps pals / slate metals / slate petals / slav ovals / sleek keels / sleeks keels / sleep peels / sleeps peels / sleepy peels / sleet steels / sleets steels / slim mils / slime mils / slims mils / sliver evils / sloop pools / sloop spools / sloops pools / sloops spools / slop pols / slope pols / slops pols / slosh sols / small lams / smart rams / smart trams / smell ems / smirk rims / smote toms / smut tums / smuts tums / snack cans / snap pans / snap spans / snaps pans / snaps spans / sneer preens / sniff fins / sniff ins / snip ins / snip pins / snip poppins / snip spins / snipe ninepins / snipe pins / snips pins / snips spins / snit ins / snivel blevins / snoops spoons / snore herons / snot tons / snots tons / snub buns / snubs buns / snugs guns / sob mambos / soda dados / soda dos / sodded dos / sol byblos / sol los / sold los / soldered los / sole los / solo gigolos / some demos / some emos / some memos / son enos / soot tattoos / sore heros / sow twos / spa caps / spa gaps / spa laps / spa maps / spa naps / spa paps / spa raps / spa saps / spa taps / spa yaps / spa zaps / space caps / space recaps / spacy caps / spams maps / span naps / span snaps / spank naps / spans naps / spans snaps / spar craps / spar raps / spar wraps / spare raps / spark raps / spars raps / spas saps / spat taps / spate taps / spats taps / spay yaps / spays yaps / speer creeps / sperm reps / spill lips / spilt lips / spin snips / spins snips / spit tips / spite tips / spits tips / spitz tips / spool loops / spool sloops / spools loops / spools sloops / spoon snoops / spoons snoops / spoor droops / spoor troops / sport strops / sports strops / spot stops / spot tops / spots stops / spots tops / sprat tarps / sprats tarps / sprawl warps / spud ups / spun ups / spy gyps / stab ats / stab bats / stabs bats / staci cats / stack cats / stacy cats / staff ats / staff fats / stag ats / stall ats / stan ats / stan gnats / staph pats / star ats / star brats / star frats / star rats / stare rats / stark rats / stars rats / start rats / state tats / stats tats / stave vats / stay ats / steel fleets / steel sleets / steels sleets / stella ballets / stella mallets / stella pallets / stella wallets / stepdad pets / stepmom pets / steps pets / stew wets / stews wets / still its / sting nits / stinks knits / stint nits / stir brits / stir grits / stir its / stir writs / stock cots / stole lots / stop pots / stop spots / stops pots / stops spots / stork rots / storm rots / story rots / strafe farts / strap parts / straps parts / strata tarts / straw warts / straws warts / stress asserts / strop ports / strop sports / strops ports / strops sports / stub abuts / stub buts / stuck cuts / stun nuts / stung nuts / stunk nuts / stuns nuts / sued amadeus / suez zeus / sumac camus / sun anus / sun gnus / sun onus / sung gnus / sups pus / suse jesus / swahili haws / swan gnaws / swap paws / swaps paws / swards draws / swash saws / sway yaws / sways yaws / swept pews / sword rows / swore rows / sworn rows / tack cat / taco cat / tact cat / taft fat / tamara mat / tame mat / tamp mat / tan gnat / tang gnat / tang nat / tangs gnat / tangy gnat / tank nat / tannin nat / tans nat / tao boat / tao goat / tao moat / tao oat / tap pat / tap spat / tape pat / taps pat / taps spat / tar ararat / tar brat / tar frat / tar rat / tara carat / tara karat / tara rat / tarawa rat / tare rat / taro rat / tarps sprat / tart rat / task sat / tass sat / tate tat / tee beet / tee feet / tee meet / teem meet / teems meet / ten net / tend net / tended net / tendered net / tenets tenet / tens net / tenses net / tent net / tepee pet / tess asset / tic illicit / tiff fit / tile lit / till lit / tilt lit / tim emit / tim mit / tim smit / time emit / time mit / timed emit / times emit / timex emit / tin knit / tin snit / tin unit / tip pit / tip spit / tipi pit / tips pit / tips spit / tipsy spit / tire merit / tito tit / tits tit / toga fagot / toga got / togo got / togs got / toil eliot / toiled eliot / toiler eliot / toilet eliot / told lot / ton knot / ton not / ton snot / tone not / tong not / toni minot / toni not / tons not / tons snot / tony not / too boot / too coot / too foot / too hoot / too loot / too moot / too soot / too toot / tool loot / tools loot / tooth toot / toots toot / top pot / top spot / tops pot / tops spot / topsy spot / tor rot / tor trot / tore diderot / tore perot / tore rot / torn rot / tors rot / torsos rot / tort rot / tort trot / torts trot / tory rot / toss sot / tosses sot / tost sot / toto tot / tots tot / town wot / trace cart / traci cart / track cart / tract cart / tracy cart / trade dart / traded art / tram art / tram kmart / tram mart / tram smart / tramp mart / trams mart / trams smart / tran art / trap apart / trap art / trap part / trapeze part / trawl wart / treble delbert / tress assert / trevor overt / trig girt / trope port / trope report / trot tort / troth tort / trots tort / truce curt / truck curt / tub abut / tub but / tubas abut / tube but / tube debut / tube rebut / tubed debut / tuber rebut / tubers rebut / tubs but / tug gut / tugs gut / tulsa slut / tums smut / tun nut / tuna nut / tune nut / tuns nut / tupi put / tutu tut / val olav / val slav / valor olav / vera rev / verb rev / vern rev / vernon rev / verses rev / versus rev / wack caw / walk law / wall law / walsh slaw / walt law / wan gnaw / wang gnaw / war craw / war draw / war raw / ward draw / ward raw / warded raw / warder redraw / warders redraw / wards draw / warn raw / warp raw / wars raw / wart raw / wart straw / warts straw / wary raw / was saw / wash saw / ways yaw / wed dew / wedded dew / weds dew / weft few / welch clew / weld lew / welded lew / well lew / welsh slew / welt lew / went new / wept pew / west sew / wet stew / wets stew / woe meow / wolf flow / wolfe flow / wolfs flow / womb mow / won know / won now / won snow / wondered now / wont now / worded row / wore row / work row / worm row / worn row / wove vow / wows wow / yahoo hay / yak kay / yak mkay / yak okay / yaks kay / yale delay / yale lay / yale relay / yam may / yamaha may / yams may / yang nay / yank nay / yap pay / yap spay / yaps pay / yaps spay / yard dray / yards dray / yaw away / yaw sway / yaws sway / yell alley / yore leroy / yore roy / york roy / you buoy / zen inez / zeus suez /