我有一个输入列表,其中REJECTED的拼写写为RE1ECTED,而DATE的写写为OATE。 我需要更正拼写并得到如下输出列表:
output_list = ["REJECTED 00000 00000","DATE TIME =06/27/18 21 37","NACH NE NO XY"]
我能够单独获取更正后的列表,但不像上面显示的那样。我可以期待一些建议吗?
input_list = ["=RE1ECTED 00000 00000",'OATE TIME =06/27/18 21 37','NACH NE NO xy']
Reg_dictionary = {"REJECTED" : ["=RE"],"DATE" : ["OA","DA"] }
for key,value in Reg_dictionary.items():
temp = [key, value]
for each_value in value:
for string_list in input_list:
count = -1
# print (count_number_of_string)
each_in_string = string_list.split(" ")
for each_word in each_in_string:
count = count + 1
if each_value in each_word:
# print (count)
# print (string_list)
# print(each_word)
# print (key)
# print(each_in_string)
(each_in_string[count]) =key
print(each_in_string)
print(each_in_string)的输出是这样的:
['REJECTED', '00000', '00000']
['DATE', 'TIME', '=06/27/18', '21', '37']
预期输出为:
output_list = ["REJECTED 00000 00000","DATE TIME =06/27/18 21 37","NACH NE NO XY"]
答案 0 :(得分:0)
您必须先将列表中的元素连接在一起,然后再将列表连接在一起。您可以使用空格将列表中的元素连接在一起,以空格作为分隔符,例如:' '.join(your_list)
,这将为您提供字符串。然后只需将2个字符串与[string_1 + ' ' + string_2
]连接在一起。那应该做的:)
答案 1 :(得分:0)
您可以执行以下操作:
FALSE