[英]Check whether a list starts with the elements of another list and if found return both the values together
我有 2 个列表:
substance = ['HYDROCHLORIC ACID 2M', 'ROPIVACAINE HYDROCHLORIDE MONOHYDRATE', 'SODIUM CHLORIDE', 'SODIUM HYDROXIDE 2M', 'WATER FOR INJECTIONS']
extracteddata = ['Ropivacaine hydrochloride monohydrate for injection (corresponding to 2 mg Ropivacaine hydrochloride anhydrous) 2.12 mg Active ingredient Ph Eur ', 'Sodium chloride for injection 8.6 mg Tonicity contributor Ph Eur ', 'Sodium hydroxide 2M q.s. pH-regulator Ph Eur, NF Hydrochloric acid 2M q.s. pH-regulator Ph Eur, NF ', 'Water for Injections to 1 ml Solvent Ph Eur, USP The product is filled into polypropylene bags sealed with rubber stoppers and aluminium caps with flip-off seals. The primary container is enclosed in a blister. 1(1)']
我想检查提取数据的哪个元素以哪个实体元素开头并将它们一起返回。
预期输出:
matchedlist = [substance:'ROPIVACAINE HYDROCHLORIDE MONOHYDRATE',extracteddata:'Ropivacaine hydrochloride monohydrate for injection (corresponding to 2 mg Ropivacaine hydrochloride anhydrous) 2.12 mg Active ingredient Ph Eur'],[substance:'SODIUM HYDROXIDE 2M', extracteddata:'Sodium hydroxide 2M q.s. pH-regulator Ph Eur, NF Hydrochloric acid 2M q.s. pH-regulator Ph Eur, NF ']
同样...
关于这个的任何帮助
这是一个可能的解决方案:
result = []
for s in substance:
for e in extracteddata:
if e.upper().startswith(s.upper()):
result.append([s, e])
print(result)
substance = ['HYDROCHLORIC ACID 2M', 'ROPIVACAINE HYDROCHLORIDE MONOHYDRATE', 'SODIUM CHLORIDE', 'SODIUM HYDROXIDE 2M', 'WATER FOR INJECTIONS']
extracteddata = ['Ropivacaine hydrochloride monohydrate for injection (corresponding to 2 mg Ropivacaine hydrochloride anhydrous) 2.12 mg Active ingredient Ph Eur ', 'Sodium chloride for injection 8.6 mg Tonicity contributor Ph Eur ', 'Sodium hydroxide 2M q.s. pH-regulator Ph Eur, NF Hydrochloric acid 2M q.s. pH-regulator Ph Eur, NF ', 'Water for Injections to 1 ml Solvent Ph Eur, USP The product is filled into polypropylene bags sealed with rubber stoppers and aluminium caps with flip-off seals. The primary container is enclosed in a blister. 1(1)']
json_data = []
for data in substance:
for data1 in extracteddata:
if data1.lower().startswith(data.lower()):
json_data.append({"substance":data,"extracteddata:":data1})
print(json_data)
希望它可能有效:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.