I have the following content in a text file.
Subject: Security alert
From: Google <no-reply@accounts.google.com>
To: example@email.com
Subject: Finish setting up your new Google Account
From: Google Community Team <googlecommunityteam-noreply@google.com>
To: example@email.com
Subject: Security alert
From: Google <no-reply@accounts.google.com>
To: example@email.com
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 <no-reply@accounts.google.com>', 'To: example@email.com']
['Subject: Finish setting up your new Google Account', 'From: Google Community Team <googlecommunityteam-noreply@google.com>', 'To: example@email.com']
['Subject: Security alert', 'From: Google <no-reply@accounts.google.com>', 'To: example@email.com']
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', '<no-reply@accounts.google.com>'], [], ['To:', 'pavan.python1393@gmail.com'], [], ['Subject:', 'Finish', 'setting', 'up', 'your', 'new', 'Google', 'Account'], [], ['From:', 'Google', 'Community', 'Team', '<googlecommunityteam-noreply@google.com>'], [], ['To:', 'pavan.python1393@gmail.com'], [], ['Subject:', 'Security', 'alert'], [], ['From:', 'Google', '<no-reply@accounts.google.com>'], [], ['To:', 'pavan.python1393@gmail.com'], [])