关注
import re
def process_main3():
row1 = raw_input()
datas = {}
entity_str_list = row1.split(";")
for entity_str in entity_str_list:
entity_name, entity_values = entity_str.split("_")
entity_value_list = entity_values.split("|")
for entity_value in entity_value_list:
if datas.has_key(entity_value):
datas[entity_value].append(entity_name)
else:
datas[entity_value] = [entity_name]
entity_list = sorted(datas.keys(), reverse=True)
row2 = raw_input()
words = row2
result = {}
tmp_words = words
temp_entity = ""
count = 1
for entity_value in entity_list:
if entity_value in tmp_words:
location = re.search(entity_value, words)
local_tuple = location.span()
if temp_entity == "":
temp_entity = entity_value
temp_tuple = local_tuple
else:
result[temp_entity] = datas[temp_entity]
tmp_words = tmp_words.replace(temp_entity, "|&{}&|".format(count))
count += 1
temp_entity = entity_value
temp_tuple = local_tuple
else:
if temp_entity != "":
result[temp_entity] = datas[temp_entity]
tmp_words = tmp_words.replace(temp_entity, "|&{}&|".format(count))
count += 1
temp_entity = ""
if temp_entity != "":
result[temp_entity] = datas[temp_entity]
tmp_words = tmp_words.replace(temp_entity, "|&{}&|".format(count))
final_list = sorted(result.keys(), reverse=True)
for index in xrange(len(final_list)):
st = ",".join(result[final_list[index]])
new_str = " " + final_list[index] + "/" + st + " "
tmp_words = tmp_words.replace("|&{}&|".format(index + 1), new_str)
print " ".join(tmp_words.split())
if __name__ == '__main__':
# main_process()
process_main3()
# singer_周杰|周杰伦|刘德华|王力宏;song_冰雨|北京欢迎你|七里香;actor_周杰伦|孙俪
# 请播放周杰伦的七里香给周杰伦周杰孙俪听周杰王力宏
查看原帖
点赞 评论
相关推荐
我恨泡池子:又原生家庭上了吗
点赞 评论 收藏
分享
胡毛毛:河师大的佬?有没有听说河南科技学院的三月软件
点赞 评论 收藏
分享
06-27 17:50
深圳大学 供应链其他 点赞 评论 收藏
分享
牛客热帖
更多
正在热议
更多
# 实习,不懂就问 #
4248次浏览 71人参与
# 小米提前批笔试难吗 #
34161次浏览 358人参与
# 现代汽车前瞻技术研发急速编程挑战赛 #
14255次浏览 145人参与
# 26届校招投递进展 #
32162次浏览 247人参与
# 央国企投递记录 #
88237次浏览 1362人参与
# 为了找工作你花了哪些钱? #
28403次浏览 268人参与
# 神州信息工作体验 #
11680次浏览 57人参与
# 校招第一份工作你干了多久? #
86184次浏览 394人参与
# 来聊聊你目前的求职进展 #
634395次浏览 6747人参与
# 考公还是考研,你怎么选? #
27801次浏览 140人参与
# 小米硬件提前批进度交流 #
168208次浏览 1523人参与
# 外包能不能当跳板? #
34558次浏览 221人参与
# 你觉得专业和学校哪个对薪资影响最大 #
61410次浏览 490人参与
# 设计人的面试记录 #
123563次浏览 1341人参与
# 打工人的精神状态 #
49936次浏览 866人参与
# 硬件人你反向读研了吗 #
42568次浏览 637人参与
# 如果中了500万,你会离职吗? #
84453次浏览 652人参与
# 你今年的保底offer是哪家 #
118527次浏览 538人参与
# 大疆的机械笔试比去年难吗 #
72965次浏览 618人参与
# 怎么评价今年的华为 #
129089次浏览 568人参与
# 硬件人秋招的第一个offer #
78008次浏览 1149人参与