我试图找出ID号,其中正文中的元音数是URL的偶数:https://jsonplaceholder.typicode.com/posts
我的代码如下:
import json
import requests
url ='https://jsonplaceholder.typicode.com/posts'
content = requests.get(url).content
j = json.loads(content)
for each in j:
print(each['id'],each['body'])
我现在可以打印每个用户ID的正文,但无法找到正文中的元音数,这是一个偶数。需要帮助吗
您可以使用以下代码计算元音:
全部代码:
输出:(每个['body']都有偶数元音的id)
下面是一个使用列表理解和
re.sub
只保留元音的解决方案:输出:
如何计算元音:
相关问题 更多 >
编程相关推荐