第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

將數字與Word分開并在Python中返回新列表

將數字與Word分開并在Python中返回新列表

qq_笑_17 2021-04-05 20:16:23
new_list = []pattern = re.compile("([0-9]+)([a-zA-Z]+)")for i, x in enumerate(my_list):    if (re.match(r"([0-9]+)([a-zA-Z]+)", x)):        result = pattern.match(x)        #result = result.group(1) + ' ' + result.group(2)        new_list.append(result.group(1))        new_list.append(result.group(2))        i = i + 2        new_list = new_list + my_list[i:]return new_list電流輸出:Input: ['2fee', 'lmao', '222wow']Output: ['2', 'fee', '222', '222wow', '222', 'wow']所需的輸出:['2', 'fee', 'lmao', '222', 'wow']如何獲得此輸出?非常感謝你
查看完整描述

2 回答

?
忽然笑

TA貢獻1806條經驗 獲得超5個贊

itertools.groupby搭配使用str.isdigit:


from itertools import groupby


L = ['2fee', 'lmao', '222wow']


res = [''.join(j) for strng in L for _, j in groupby(strng, key=str.isdigit)]


# ['2', 'fee', 'lmao', '222', 'wow']

請注意,這將拆分出現在字符串中的每個數字實例。例如,'1a23bc'將被分割為'1','a','23','bc'。


查看完整回答
反對 回復 2021-04-27
?
HUWWW

TA貢獻1874條經驗 獲得超12個贊

或者,嘗試:


import re

input = ['2fee', 'lmao', '222wow']

output = []

for s in input:

    output.extend(t for t in re.split('(\d+)', s) if t)

print output


查看完整回答
反對 回復 2021-04-27
  • 2 回答
  • 0 關注
  • 216 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號