[Tutor] Need help - getting Tuple index out of range

Alex Kleider akleider at sonic.net
Wed Feb 5 12:25:49 EST 2020


On 2020-02-04 21:34, Abhinava Saha wrote:
> Hi all,
> 
> I am a beginner in python, Someone please help me fix the program
> below on tuple, getting error touple index out of range.
> 
> def full_email(peoples):
>     result = []
>     for index, (name, email) in enumerate(peoples):
>         result.append("{} <{}>".format("name, email"))
>     return result
> 
> print(full_email([('Abhinava', 'abhinava at abc.com'), ('Manoj',
> 'manoj at xyz.com')]))

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')]))
"""


More information about the Tutor mailing list