我正在尝试使用Python字典对输入字符串中的列和值(column=value)进行有意义的分类。你知道吗
input_string = "the status is processing and product subtypes are HL year 30 ARM and applicant name is Ryan"
我已经创建了键值对字典。在第一个场景中,键是列名。值表示在input_string
中找到的键的最低索引。你知道吗
这是列名词典:
dict_columns = {'status': 4, 'product subtypes': 29, 'applicant name': 69}
在上面的字典中,'status'
在input_string
中有最低的4
索引。你知道吗
类似地,这里是值字典:
dict_values = {'processing': 14, 'hl': 50, 'year': 53, '30': 58, 'arm': 61, 'ryan': 87}
问题是:
如何获得预期输出:
list_parsed_values = ['processing', 'hl year 30 arm', 'ryan']
和相应的列列表(可选):
list_parsed_columns = ['status', 'product subtypes', 'applicant name']
如何清晰区分列表中的值?
检查以下方法:
dict_columns
键构建正则表达式以拆分文本以下是我迄今为止的代码:
相关问题 更多 >
编程相关推荐