社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
私信  •  关注

SmartManoj

SmartManoj 最近创建的主题
SmartManoj 最近回复了
6 年前
回复了 SmartManoj 创建的主题 » python 3中列表中的特定模式字符串

使用regex

import re
ZTon = ['one-- and preferably only one --obvious', " Hello World", 'Now is better than never.', 'Although never is often better than *right* now.']
pattern=r'(--|\*)(.*)\1'
l=[]
for line in ZTon:
    s=re.search(pattern,line)
    if s:l.append(s.group(2).strip())
print (l)
# ['and preferably only one', 'right']
6 年前
回复了 SmartManoj 创建的主题 » 在python中递增月份,然后打印递增月份的名称

对于像十二月这样的边缘案例 calendar.month_name 有13个元素

import calendar
import datetime
months=calendar.month_name[1:]
a=months[datetime.date.today().month % 12]
print(a)