Sending invitations to a list of people

338 Views Asked by At

I have the following list of people I would like to invite for dinner:

guests = ["Ava Lovelace", "Epictetus", "Buddha", "Einstein"]

I would like to send an invite to each of them, but without mentioning their own name in the invite. Here is what I tried (and got an error):

for i in guests:
    print (f"{i}, would you like to have dinner together? The following people received an invitation:", guests.replace("{i}"), "you")

1

There are 1 best solutions below

0
Hiibb On

The replace function doesn't exist for lists in python. You could try a list comprehension instead:

for i in guests:
    guest_list = [guest if guest != i else "you" for guest in guests]
    print (f"{i}, would you like to have dinner together? The following people received an invitation: {guest_list}")