I have the following content in a text file.
Subject: Security alert
From: Google <[email protected]>
To: [email protected]
Subject: Finish setting up your new Google Account
From: Google Community Team <[email protected]>
To: [email protected]
Subject: Security alert
From: Google <[email protected]>
To: [email protected]
I would like to store the first three lines in a tuple, and next 3 lines in an another tuple and so on, like below. [expected output]
['Subject: Security alert', 'From: Google <[email protected]>', 'To: [email protected]']
['Subject: Finish setting up your new Google Account', 'From: Google Community Team <[email protected]>', 'To: [email protected]']
['Subject: Security alert', 'From: Google <[email protected]>', 'To: [email protected]']
I tried with the following code, however I am missing in how to take "each line" rather than "each word" as I tried below.
with open('input.txt') as f:
result = map(str.split, f)
t = tuple(result)
print(t)
# Unexpected output
(['Subject:', 'Security', 'alert'], [], ['From:', 'Google', '<[email protected]>'], [], ['To:', '[email protected]'], [], ['Subject:', 'Finish', 'setting', 'up', 'your', 'new', 'Google', 'Account'], [], ['From:', 'Google', 'Community', 'Team', '<[email protected]>'], [], ['To:', '[email protected]'], [], ['Subject:', 'Security', 'alert'], [], ['From:', 'Google', '<[email protected]>'], [], ['To:', '[email protected]'], [])