This is the sample code:
my_list = [
{'name': 'Saeed', 'source_country': 'IR', 'destination_country': 'IT', 'email': '[email protected]'},
{'name': 'Vahid', 'source_country': 'US', 'destination_country': 'DE', 'email': '[email protected]'},
{'name': 'Ali', 'source_country': 'UK', 'destination_country': 'JP', 'email': '[email protected]'},
{'name': 'Joe', 'source_country': 'FR', 'destination_country': 'KR', 'email': '[email protected]'},
]
html = 'n'.join([f"<p>{b.replace('_', ' ').title()}: {p[b]}</p>" for p in my_list for b in p])
This is current output:
>>> print(html)
<p>Name: Saeed</p>
<p>Source Country: IR</p>
<p>Destination Country: IT</p>
<p>Email: [email protected]</p>
<p>Name: Vahid</p>
<p>Source Country: US</p>
<p>Destination Country: DE</p>
<p>Email: [email protected]</p>
<p>Name: Ali</p>
<p>Source Country: UK</p>
<p>Destination Country: JP</p>
<p>Email: [email protected]</p>
<p>Name: Joe</p>
<p>Source Country: FR</p>
<p>Destination Country: KR</p>
<p>Email: [email protected]</p>
I’m going to have this (expected output):
<p>Name: Saeed, Source Country: IR, Destination Country: IT, Email: [email protected]</p>
<p>Name: Vahid, Source Country: US, Destination Country: DE, Email: [email protected]</p>
<p>Name: Ali, Source Country: UK, Destination Country: JP, Email: [email protected]</p>
<p>Name: Joe, Source Country: FR, Destination Country: KR, Email: [email protected]</p>
How can I store and print the expected output?