
Python
numbers = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]您可以使用Python中的列表推导式来筛选出所有小于60的数字:Pythonsmall_numbers = [x for x in numbers if x < 60]print(small_numbers)2. 对于文本数据:假设您有以下文本数据,并且希望筛选出所有包含关键字"China"或者"Chinese"的内容:text = ["China is a beautiful country","Chinese culture is rich","The Great Wall of China is famous"]您可以使用Python中的字符串方法isupper()和find()来实现筛选功能:Pythonresult = []for s in text: if s.isupper() and s.find("China") != -1 or s.find("Chinese") != -1: result.append(s)print(result)以上是两种常见的解决方案,希望对您有所帮助!Copyright © 2025 IZhiDa.com All Rights Reserved.
知答 版权所有 粤ICP备2023042255号