我在点击栏中有以下数据:
MEM-BEN-BTN-CLK-entertainment-audible
MEM-BEN-LOC-MODAL-LOCATION-INPUT-Birmingham, AL, USA
MEM-BEN-BTN-CLK-entertainment-games
MEM-BEN-BTN-CLK-healthandwellness-love-and-meaning-after-50
MEM-BEN-BTN-LRN-learn-more-aarp-travel-center-powered-by-expedia-10083
MEM-BEN-BTN-LRN-learn-more-embassy-suites-by-hilton-1019
我想将列单击拆分为两列单击上部和下部
单击上方(保留所有大写字符)
MEM-BEN-BTN-CLK
MEM-BEN-LOC-MODAL-LOCATION-INPUT
MEM-BEN-BTN-CLK
MEM-BEN-BTN-CLK
MEM-BEN-BTN-LRN
MEM-BEN-BTN-LRN
单击\u lower(保存所有小写字符)
entertainment-audible
Birmingham, AL, USA
entertainment-games
healthandwellness-love-and-meaning-after-50
learn-more-aarp-travel-center-powered-by-expedia-10083
learn-more-embassy-suites-by-hilton-1019
我试图使用split()函数,但是有多个分隔符(-),并且字符串的长度不同,因此代码对我不起作用。我也试过了,但它断了线
如果能在这方面得到任何指导或帮助,我将不胜感激
让
split
在text
后面加上-
再加上lower case
或-
再加上string Startingwithcaps but followed with lowercase letters
分割之后,我们可以切片
first element in list
,这将给我们upper
一旦我们有了上限,
remove the upper
从全文中保留lower
下面的代码和享受编码
资料
代码
我使用regex语句来拆分字符串。您可以使用re.group(x)方法访问这两个组。这里有更多信息:https://docs.python.org/3/library/re.html
以下是输出:
相关问题 更多 >
编程相关推荐