Skip to content

Instantly share code, notes, and snippets.

@laat
Forked from anonymous/o3.py
Created September 6, 2010 16:15
Show Gist options
  • Save laat/567206 to your computer and use it in GitHub Desktop.
Save laat/567206 to your computer and use it in GitHub Desktop.
from sys import stdin
import re
__author__="Jonas Svarvaa"
__date__ ="$06.sep.2010 12:39:53$"
def parse_input():
words = {}
pos = 0
for s in stdin.readline().split():
try:
words[s].append(pos)
except:
words[s]=[pos]
pos += len(s) + 1
for s in stdin:
s = s.strip()
print s+":"+find_pos(s, words)
def find_pos(string, list):
l = len(string)
o = ""
if string in list:
for x in list[string]:
o+=" "+str(x)
for k,v in list:
if "?" in string:
#if l == len(k) :
# wc = string.find("?", 0, l)
# if (string[0:wc] == k[0:wc]) and (string[wc+1:] == k[wc+1:]):
# o += " " + str(v)
newstr = ""
for c in string:
if c == "?":
c = "."
newstr += c
if re.search(newstr, k) and len(k) == len(newstr):
o += " " + str(v)
elif string == k:
o += " " + str(v)
return o
if __name__ == "__main__":
parse_input()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment