def between(a, b, f="/usr/share/dict/words"): poss=[] fd=open(f,"r") line=fd.readline() for line in fd: word = line.strip() if word > b: break if word > a: poss.append(word) fd.close() return poss def between_s(a): parts=a.split() return between(parts[0], parts[2]) bs = between_s import sys import math import random line=sys.stdin.readline() while line: poss = bs(line.strip()) if len(poss) <= 8: print poss line=sys.stdin.readline() continue print len(poss) center = int(math.floor(len(poss)/2)) print poss[ center - 1 ], poss[ center ], poss[ center + 1 ], \ poss[ center + random.randint(-int(center/3),int(center/3)) ] line=sys.stdin.readline()