[Tutor] Need help - getting Tuple index out of range
Mats Wichmann
mats at wichmann.us
Wed Feb 5 13:18:43 EST 2020
On 2/5/20 10:25 AM, Alex Kleider wrote:
> On 2020-02-04 21:34, Abhinava Saha wrote:
> You are not using the index provided by enumerate so I suggest you get
> rid of it.
> The error you are getting is because your format string requires two
> parameters (one for each {}) and you've only provided one ("name, email").
> Change "name, email" which is one string to the two variables you want:
> name and email.
> The following works:
> """
> def full_email(peoples):
> result = []
> for (name, email) in peoples:
> result.append("{} <{}>".format(name, email))
> return result
>
> print(full_email([('Abhinava', 'abhinava at abc.com'), ('Manoj',
> 'manoj at xyz.com')]))
> """
And if you are able to ensure a recent Python version, you can use
f-strings to write it in a way there isn't likely to be any confusion:
result.append(f"{name} <{email}>")
More information about the Tutor
mailing list