Most Pythonic Way to Split an Array by Repeating Elements

前端 未结 11 1277
星月不相逢
星月不相逢 2021-02-13 09:51

I have a list of items that I want to split based on a delimiter. I want all delimiters to be removed and the list to be split when a delimiter occurs twice. F

11条回答
  •  别那么骄傲
    2021-02-13 10:09

    import re    
    map(list, re.sub('(?<=[a-z])X(?=[a-z])', '', ''.join(lst)).split('XX'))
    

    This does a list -> string -> list conversion and assumes that the non-delimiter characters are all lower case letters.

提交回复
热议问题