我有两段文字。我必须用python从这两个段落中找出共同的词

2024-04-29 12:14:46 发布

您现在位置:Python中文网/ 问答频道 /正文

第1段

电子商务,通常被称为电子商务,是利用计算机网络,如互联网或在线社交网络,对商品或服务进行交易或便利化。电子商务利用了移动商务、电子资金转移、供应链管理、互联网营销、在线交易处理、电子数据交换(EDI)、库存管理系统和自动数据收集系统等技术。你知道吗

第2段

现代电子商务通常在交易生命周期的至少一部分使用万维网,尽管它也可能使用电子邮件等其他技术。电子商务的好处包括它的访问速度、更广泛的商品和服务选择、可访问性和国际影响力。你知道吗

我得找出两段文字的共同点,然后打印出来


Tags: 网络利用库存电子互联网交易技术商品
2条回答

您可以使用set.intersection。你知道吗

p1 = '''
Electronic commerce, commonly written as E-Commerce, is the trading or  
facilitation of trading in goods or services using computer networks, such 
as the Internet or online social networks. Electronic commerce draws on 
technologies such as mobile commerce, electronic funds transfer, supply 
chain management, Internet marketing, online transaction processing, 
electronic data interchange (EDI), inventory management systems, and 
automated data collection systems.
'''.split()

p2 = '''
Modern electronic commerce typically uses the World Wide Web for at least 
one part of the transaction's life cycle although it may also use other 
technologies such as e-mail. The benefits of e-commerce include it’s the 
speed of access, a wider selection of goods and services, accessibility, and 
international reach.
'''.split()

print(set(p1).intersection(p2))
{'and', 'the', 'technologies', 'of', 'electronic', 'such', 'commerce', 'as', 'goods'}

如果您不需要在语言处理方面做一些特殊的事情,那么您就不需要NLTK:

paragraph1 = paragraph1.lower().split()
paragraph2 = paragraph2.lower().split()

intersection = set(words1) & set(words2)

相关问题 更多 >