with open("input_file.txt") as f:
lines = f.readlines()
# It will going to split string from every dot and comma
result = [tuple(l.strip().replace(',', '.').split(".")) for l in lines]
# Result: [('TEST', 'JOB'), ('TEST', 'LAST_LOGIN', '10'), ('TEST', 'DATA', '12'), ('TEST', 'QUEUE_PARAM', '09'), ('TEST', 'ENTITY_PROFILE')]
lst = ['TEST.JOB',
'TEST.LAST_LOGIN,10',
'TEST.DATA,12',
'TEST.QUEUE_PARAM,09',
'TEST.ENTITY_PROFILE']
result = [tuple(line.replace('.',' ').replace(',',' ').split()) for line in lst]
print(result)
# extract date into list of lists prior to this logic
lst = ['TEST.JOB',
'TEST.LAST_LOGIN,10',
'TEST.DATA,12',
'TEST.QUEUE_PARAM,09',
'TEST.ENTITY_PROFILE']
# initialise list
res = []
# iterate and append
for item in lst:
cat, detail = item.split('.')
app = [cat] + detail.split(',')
res.append(app)
# convert list of lists to list of tuples
res = list(map(tuple, res))
我刚刚编辑了Yassine Faris的帖子,但是被删除了。这实际上是一个正确的答案,缺乏代码。你知道吗
简单的一行:
结果:
这是一种方法。你知道吗
结果:
相关问题 更多 >
编程相关推荐