簡體   English   中英

如何從你拆分的字符串中獲取列表?

[英]How to get list from string which you pre splitted?

所以有一個字符串foo = 'asdfasdfzxc<test>afx<one>'
如何獲得bar = ['asdfasdfzxc','test','afx','one']

嘗試,

import re
foo = 'asdfasdfzxc<test>afx<one>'
bar = re.split(r'[\<\>]',foo)[:-1]
bar.remove('afx')

bar
Out[89]:
['asdfasdfzxc', 'test', 'one']

嘗試這個

foo = 'asdfasdfzxc<test>afx<one>'
bar= foo.replace('<','>').split('>')[:-1]
del bar[2]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM