简体   繁体   English

根据python中的位置值组合列表中的数据

[英]combine data in list based on location value in python

I have lists in Python.我在 Python 中有列表。 Simple representation is as below with title Input.简单的表示如下,标题输入。 How can I identify 2 term location( Eg 'las' 'vegas') and combine them to achieve a location with single term( eg 'lasvega') .我如何识别 2 个术语位置(例如 'las' 'vegas')并将它们组合起来以实现具有单个术语的位置(例如 'lasvega')。 Desired output as show below order of input list is always randomized.如下所示的所需输出输入列表的顺序始终是随机的。 Any pointers on how I can achieve will be appreciated.任何关于我如何实现的指示将不胜感激。

Input:输入:

['vegas' , 'hotel' , 'las']
['new' , 'york' , 'flights']
['san' , 'accomodations' , 'franscisco']
['san' , 'diego' , 'motel']

Desired output:期望的输出:

['lasvegas' , 'hotel' ]
['newyork' , 'flights']
['sanfranscisco' , 'accomodations' ]
['sandiego' , 'motel']

What you want is full-text search.你想要的是全文搜索。 If the dataset you have is really large or there are performance concerns, you should consider a tailor-made solution like Elastic Search or Solr or som suitable database.如果您拥有的数据集非常大或存在性能问题,您应该考虑量身定制的解决方案,例如Elastic SearchSolr或一些合适的数据库。

If you only want a simple solution in Python, then you first need to maintain a dictionary of all the cities in the world.如果你只想要一个简单的 Python 解决方案,那么你首先需要维护一个世界上所有城市的字典。 After that you can find all combinations of strings in list ie powerset of the list and loop over the powerset to find which combinations exist in before mentioned city dictionary.之后,您可以在列表中找到所有字符串组合,即列表的 powerset 并循环遍历 powerset 以查找前面提到的城市词典中存在哪些组合。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM