Python中文
首页
教程
问答
标签
搜索
登录
注册
Python:使用startswith、endswith和lengh从列表中获取所有发生的事件
回答此问题可获得
20
贡献值,回答如果被采纳可获得
50
分。
<p>我想在我的词表中搜索一些条件。你知道吗</p> <p>这是我代码的一部分:</p> <pre><code># -*- coding: utf-8 -*- with open(r"C:\Users\Valentin\Desktop\list.txt") as f: content = f.readlines() content = [x.strip() for x in content] all_words = ','.join(content) end = all_words.endswith('e') </code></pre> <p>我的清单如下:</p> <blockquote> <p>'cresson', 'crête', 'Créteil', 'crétin', 'creuse', 'creusé', 'creuser',...</p> </blockquote> <p>我想设置这些条件:</p> <ul> <li>以字母“C”开头</li> <li>以字母“E”结尾</li> <li>长度:9个字符</li> </ul> <p>我怎么能做到?你知道吗</p>
0 条评论
分类:
Python问答
请先
登录
后评论
默认排序
时间排序
1 个回答
匿名
1天前
擅长:python、mysql、java
<p>假设不区分大小写,并且您可以访问f字符串(Python3.6):</p> <pre><code>[s for s in content if len(s) == 9 and f'{s[0]}{s[-1]}'.lower() == 'ce'] </code></pre>
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
无法使用Django/mongoengine连接到MongoDB(身份验证失败)
10 回答
无法使用Django\u mssql\u后端迁移到外部hos
5 回答
无法使用Django&Python3.4连接到MySql
3 回答
无法使用Django+nginx上载媒体文件
5 回答
无法使用Django1.6导入名称模式
8 回答
无法使用Django1.7和mongodb登录管理站点
1 回答
无法使用Djangoadmin创建项目,进程使用了错误的路径,因为我事先安装了错误的Python
2 回答
无法使用Djangockedi验证CBV中的字段
5 回答
无法使用Djangocketditor上载图像(错误400)
10 回答
无法使用Djangocron进行函数调用
9 回答
无法使用Djangofiler djang上载文件
7 回答
无法使用Djangokronos
9 回答
无法使用Djangomssql provid
10 回答
无法使用Djangomssql连接到带有Django 1.11的MS SQL Server 2016
9 回答
无法使用Djangomssq迁移Django数据库
3 回答
无法使用Djangonox创建用户
10 回答
无法使用Djangopyodb从Django查询SQL Server
6 回答
无法使用Djangopython3ldap连接到ldap
10 回答
无法使用Djangoredis连接到redis
4 回答
无法使用Django中的FK创建新表
3 回答