如何从python列表的每个元素中删除前缀?

如何从python列表的每个元素中删除前缀?,python,regex,list,Python,Regex,List,我有一个python列表,其中的项目如下: [ 1.1 ] 1. a electronic bill presentment system. [ 1.2 ] a network. [ 1.3 ] a plurality of first stations, each associated with a respective one of a plurality of users and operable to transmit first requests for bills of its as

我有一个python列表,其中的项目如下:

[ 1.1 ] 1. a electronic bill presentment system.
[ 1.2 ] a network.
[ 1.3 ] a plurality of first stations, each associated with a respective one of a plurality of users and operable to transmit first requests for bills of its associated user via the network.
[ 1.4 ] a central network station configured to receive the transmitted first requests for bills and to transmit, responsive to each of the received first requests, bill availability information for the associated user via the network, wherein each of the plurality of first stations is configured to receive the transmitted bill availability information for its associated user and is operable to transmit second requests for bills of its associated user via the network.
[ 1.5 ] a plurality of second network stations, each associated with a respective one of a plurality of billers, configured to receive the transmitted second requests for bills and to transmit, responsive thereto, the requested bills of the associated user via the network.
[ 1.6 ] wherein the bill availability information for the associated user identifies those of the plurality of billers having a bill available for that user without identifying an amount of the bill of each of the identified billers for the associated user.
[ 2.1 ] 2. a method for presenting electronic bills.
[ 2.2 ] storing, at a plurality of different locations, electronic bills of a plurality of different billers for a plurality of different users.
[ 2.3 ] storing identifiers of the stored electronic bills at a location different than the plurality of different locations.
[ 2.4 ] transmitting a first request for the stored electronic bills for a first of the plurality of users.
[ 2.5 ] transmitting one or more of the stored identifiers of the stored electronic bills for the first user responsive to the transmitted first request, each of the transmitted one or more identifiers being associated with a respective one of the stored electronic bills of a different one of the plurality of billers.
[ 2.6 ] transmitting a second request for at least one of the stored electronic bills identified by the transmitted one or more identifiers.
[ 2.7 ] transmitting the at least one identified stored electronic bill responsive to the transmitted second request.
[ 2.8 ] wherein the transmitted one or more identifiers identifies the stored electronic bills without identifying an amount of the identified stored electronic bills.
所有我需要的是删除前缀从每个项目,但不知道如何删除这个

比如说,

我需要删除
[2.8](空格)[2.7](空格)
。上面的每一个新行表示列表中的项目。 也类似于
[1.1]1。电子票据提示系统。
,我需要删除
[1.1]1。

我要删除的代码函数如下所示,我使用一个逻辑首先使用空格分割,然后删除非alpha值

但它不能正常工作

请帮忙

TextDictionaryValuesList = list(TextDictionary.values()) 
# You can make a test list using above given items of mylist

def remove_non_alpha(splitlist):
    for j in range(0, len(splitlist)):
        if(splitlist[j].isalpha()):
            splitlist[j] = splitlist[j]
        else:
            splitlist[j] = ""       

    return splitlist


for i in range(0, len(TextDictionaryValuesList)):

    print(TextDictionaryValuesList[i])

    splitlist = TextDictionaryValuesList[i].split(" ")
    splitlist = remove_non_alpha(splitlist)
    TextDictionaryValuesList[i] = splitlist

print(TextDictionaryValuesList)
这里有一种方法使用:


使用更大的字符串列表进行测试:

l = ['[ 1.1 ] 1. a electronic bill presentment system.',\
'[ 1.2 ] a network.',\
'[ 1.3 ] a plurality of first stations, each associated with a respective one of a plurality of users and operable to transmit first requests for bills of its associated user via the network.',\
'[ 1.5 ] a plurality of second network stations, each associated with a respective one of a plurality of billers, configured to receive the transmitted second requests for bills and to transmit, responsive thereto, the requested bills of the associated user via the network.',\
'[ 1.6 ] wherein the bill availability information for the associated user identifies those of the plurality of billers having a bill available for that user without identifying an amount of the bill of each of the identified billers for the associated user.',\
'[ 2.1 ] 2. a method for presenting electronic bills.']

[re.sub(r'\[\s*\d+\.*\d*\s*\]\s+(?:\d+\.\s*)?', '', s) for s in l]

['a electronic bill presentment system.',
 'a network.',
 'a plurality of first stations, each associated with a respective one of a plurality of users and operable to transmit first requests for bills of its associated user via the network.',
 'a plurality of second network stations, each associated with a respective one of a plurality of billers, configured to receive the transmitted second requests for bills and to transmit, responsive thereto, the requested bills of the associated user via the network.',
 'wherein the bill availability information for the associated user identifies those of the plurality of billers having a bill available for that user without identifying an amount of the bill of each of the identified billers for the associated user.',
 'a method for presenting electronic bills.']
这里有一种方法使用:


使用更大的字符串列表进行测试:

l = ['[ 1.1 ] 1. a electronic bill presentment system.',\
'[ 1.2 ] a network.',\
'[ 1.3 ] a plurality of first stations, each associated with a respective one of a plurality of users and operable to transmit first requests for bills of its associated user via the network.',\
'[ 1.5 ] a plurality of second network stations, each associated with a respective one of a plurality of billers, configured to receive the transmitted second requests for bills and to transmit, responsive thereto, the requested bills of the associated user via the network.',\
'[ 1.6 ] wherein the bill availability information for the associated user identifies those of the plurality of billers having a bill available for that user without identifying an amount of the bill of each of the identified billers for the associated user.',\
'[ 2.1 ] 2. a method for presenting electronic bills.']

[re.sub(r'\[\s*\d+\.*\d*\s*\]\s+(?:\d+\.\s*)?', '', s) for s in l]

['a electronic bill presentment system.',
 'a network.',
 'a plurality of first stations, each associated with a respective one of a plurality of users and operable to transmit first requests for bills of its associated user via the network.',
 'a plurality of second network stations, each associated with a respective one of a plurality of billers, configured to receive the transmitted second requests for bills and to transmit, responsive thereto, the requested bills of the associated user via the network.',
 'wherein the bill availability information for the associated user identifies those of the plurality of billers having a bill available for that user without identifying an amount of the bill of each of the identified billers for the associated user.',
 'a method for presenting electronic bills.']

您应该使用正则表达式用空字符串替换模式

>>> re.sub(r'\[\s?\d\.\d\s?]\s?(\d(\.\s)?)?', '', '[ 1.1 ] 1. a electronic bill presentment system.')
'a electronic bill presentment system.'

您应该使用正则表达式用空字符串替换模式

>>> re.sub(r'\[\s?\d\.\d\s?]\s?(\d(\.\s)?)?', '', '[ 1.1 ] 1. a electronic bill presentment system.')
'a electronic bill presentment system.'

如果你不想避免使用正则表达式,只要你没有像
[1.2.b]
这样别致的前缀或任何带有字母的前缀,你就可以保持简单

def chop_non_alpha(txt):
    for i in range(len(txt)):
        if txt[i].isalpha():
            return txt[i:]

for line in lines:
    print(chop_non_alpha(line))

如果你不想避免使用正则表达式,只要你没有像
[1.2.b]
这样别致的前缀或任何带有字母的前缀,你就可以保持简单

def chop_non_alpha(txt):
    for i in range(len(txt)):
        if txt[i].isalpha():
            return txt[i:]

for line in lines:
    print(chop_non_alpha(line))

这看起来像一个课堂/作业问题。你熟悉正则表达式吗?是的,我知道正则表达式,但它不能使用。这看起来像是一个课堂/作业问题。你熟悉正则表达式吗?是的,我知道reg表达式,但它不能使用答案中所示的ITA,这不会删除前导1。在方括号之后。如答案所示,这不会删除前导1。在方括号之后。此链接是否自动创建Reg exp No,用于在样本字符串@RinkuYadavI上测试正则表达式。我对使用的量词很好奇。我将使用
+
表示小数,
*
表示空格。我想至少改变一下
\d?
fairpoint@adrio
*
在这里做得更有意义,再仔细考虑一下。这仅仅是因为似乎总共最多只有一个空间cases@yatu如果我只想删除
1怎么办[1.1]1中的
]
之后添加code>
,什么可以是正则表达式,并且只保留
[1.1]
是此链接自动创建Reg exp No,用于在示例字符串@RinkuYadavI上测试正则表达式。我对使用的量词很好奇。我将使用
+
表示小数,
*
表示空格。我想至少改变一下
\d?
fairpoint@adrio
*
在这里做得更有意义,再仔细考虑一下。这仅仅是因为似乎总共最多只有一个空间cases@yatu如果我只想删除
1怎么办[1.1]1中的
]
之后添加code>
,什么可以是正则表达式,并且只保留
[1.1]