反向搜索相似字符串列表的最佳方法
我有一个数据列表,其中包括命令字符串以及字母表(大写和小写),总共 512 个以上(包括子列表)字符串。我想解析输入数据,但除了从最大可能的命令大小开始并将其缩小直到找到与字符串相同的命令然后输出的位置之外,我想不出任何方法可以正确执行此操作命令,但这需要很长时间。我能想到的任何其他方式都会导致重叠。我在 python 中这样做
说:
L = ['a', 'b',['aa','bb','cc'], 'c']
对于“bb”,输出将是“0201”,“c”将是“03”,
那么我应该怎么做?
I have a list of data that includes both command strings as well as the alphabet, upper and lowercase, totaling to 512+ (including sub-lists) strings. I want to parse the input data, but i cant think of any way to do it properly other than starting from the largest possible command size and cutting it down until i find a command that is the same as the string and then output the location of the command, but that takes forever. any other way i can think of will cause overlapping. im doing this in python
say:
L = ['a', 'b',['aa','bb','cc'], 'c']
for 'bb' the output would be '0201' and 'c' would be '03'
so how should i do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
听起来您正在列表中搜索每个子字符串。您构建一个字典来查找键怎么样?当然,您仍然必须从最长的子项开始搜索。
然后,您可以使用以下命令查找子字符串:
但如果密钥长度不仅仅是 1 或 2,则将项目分组到每个密钥具有相同长度的单独字典中也可能是有意义的。
It sounds like you're searching through the list for every substring. How about you built a dict to lookup the keys. Of cause you still have to start searching at the longest subkey.
You could then lookup substrings with:
But if the key length is not just 1 or 2, it might also make sense to group the items into separate dicts where each key has the same length.
如果你必须使用这个数据结构:
但是
这是一个糟糕的数据结构。您能以更好的形式获取这些数据吗?
If you must use this data structure:
BUT
This is a bad data structure. Are you able to get this data in a nicer form?