我有一个包含如下项目的 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](space) [2.7](space)。上面的每个新行打印代表列表的项目。 也像 [ 1.1 ] 1. 电子账单呈现系统。,我需要删除 [ 1.1 ] 1.
我的代码函数如下所示,我使用的逻辑是先使用空格拆分,然后删除非字母值。
但是它不能正常工作。
请帮忙。
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)
请您参考如下方法:
这是使用 re.sub 的一种方法:
import re
l = ['[ 1.1 ] 1. a electronic bill presentment system.','[ 1.2 ] a network.']
[re.sub(r'\[\s*\d+\.*\d*\s*\]\s+(?:\d+\.\s*)?', '', s) for s in l]
# ['a electronic bill presentment system.', 'a network.']
参见 demo
使用更大的字符串列表进行测试:
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.']
