Skip to content

Instantly share code, notes, and snippets.

Created September 6, 2010 15:55
Show Gist options
  • Save anonymous/567181 to your computer and use it in GitHub Desktop.
Save anonymous/567181 to your computer and use it in GitHub Desktop.
from sys import stdin
__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
print words
for s in stdin:
s = s.strip()
if s in words:
print s+": "+" ".join(map(str, words[s]))
else:
print s+": "+str(mypos(s, 0, words))
def mypos(needle, index, nodes):
if "?" in needle:
c = needle.count("?")
pos = 0
w = []
for c2 in range(c):
pos += needle[pos:].find("?")+1
w.append(pos-1)
print w
else:
return ""
if __name__ == "__main__":
parse_input()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment