The below code summarizes and uses different list functions for practice.
Part 1: Make a list of guests and invite them to your birthday party.
# Guest Invitations
## Making list of guests to invite on birthday party
> guests = ['Donny', 'Johnny', 'Sonny', 'Ronny', 'Tonny', 'Bonny', 'Monny']
## Invite them to the Birthday Party
> for guest in guests:
print(f'Hi, {guest}! You are cordially invited to my Birthday Party!\n')
Explanation:
The above code uses easier syntax to create a new list (first line of code). It’s easier to use because the number of elements is finite and very small. In case of a large number of elements, use the ‘list comprehension‘ or ‘list‘ function.
The 2nd line of code uses a ‘for‘ loop on the guests list created above and generates the invite, one by one.
Result:

Part 2: One of the guests can’t make it to the party. State one of the guests who can’t make it to the party. Invite a new person instead, and update the rest of the guests about the changes.
## Part 2
## Stating the name of the guest, who can't make it to the party.
> guest_skipped = guests.pop(2)
> print(f'{guest_skipped} cannot make it to the party.\n')
## Invite a new person
> new_guest = 'Xena'
> print(f'Hello {new_guest}! You are cordially invited to my Birthday Party!\n')
## Update rest of the invited guests
> for guest in guests:
print(f'Hello {guest}. {guest_skipped} cannot make it to the party. {new_guest} is invited in place.\n')
## Update the list with new guest
> guests.append(new_guest)
> print(guests)
Explanation:
The first line pops or removes the desired guest – in this case, a guest at index 2 (3rd place) – from the list and stores it into a variable.
The second line prints which guest is not able to make it to the party.
The third line stores the name of a new person in a variable, which then is invited in the fourth line.
The fifth line uses a ‘for‘ loop to send this update to the rest of the guests on the list.
The sixth line appends the new person to the guest list and prints out the final list of the guests invited to the party.
Result:

Part 3: You managed a larger budget for your birthday and can afford a bigger place to organize. Invite 5 more guests to the party. Send the rest of the guests an update about the event.
## Part 3
## Creating new list with 5 additional guests
> new_5_guests = ['Luv', 'Kush', 'Ram', 'Neelu', 'Vishakha']
## Updating the previous guests about the event
> for guest in guests:
print(f'Dear {guest}, I have found a bigger place for the party. Therefore, I am inviting 5 new guests to the party.\n')
## Inviting 5 new guests to the party and updating the 'guests' list
> for guest in new_5_guests:
print(f'Hello {guest}! You are cordially invited to the Birthday Party!\n')
guests.append(guest)
> print(guests)
Explanation:
Line 1 creates a new list containing 5 new guests and assign it to a variable.
Line 2 runs a ‘for‘ loop to iterate over old guests list and provide update about the new place and 5 new guests.
Line 3 runs a ‘for‘ loop to iterate over new guest list and print invite message. Also, it appends the new guests to ‘guests‘ list.
Line 4 prints complete and updated guest list.
Result:

Final Part: Your boss at your secret organization has assigned you a secret spy mission in some other country. Unfortunately, it falls around your birthday. You have to cancel the birthday party to serve your country. Although, 2 of the guests are your colleagues and you can still arrange a secret party while on the mission. Choose any 2 guests and update them about the changes. Update the rest about the cancellation of the party with a personalized message.
## Final Part
> colleagues = ['Johnny', 'Xena']
> to_remove = []
> for guest in guests:
if guest in colleagues:
continue
print(f"Dear {guest}, I'm cancelling the party due unforeseen circumstances! Apologies!\n")
to_remove.append(guest)
> for guest in to_remove:
if guest in guests:
guests.remove(guest)
print(f"<<<{guest} removed from the list>>>")
> to_remove.clear()
> print(f"\nGuest list has: {guests}\n")
> for guest in guests:
print(f"Hi, {guest}! There have been change of plans. I'll reorganize my birthday party as per our itenerary. I'll keep you updated.\n")
Explanation:
Line 1 creates a list of colleagues working on same mission
Line 2 creates an empty list to store guests’ name to be removed from guests list.
Line 3 uses ‘for‘ loop to iterate over guest list. this loop instructs to compare if the currect guest name matches with any of the name in colleagues list. If matched, skip the current iteration and do nothing. Otherwise, print an apology message and append the guest name to to_remove list.
Line 4 uses ‘for‘ loop to iterate over to_remove list and match the guest name with the elements of guests list. if matched, remove the name from guests list and state the action.
Line 5 clears all the elemts from to_remove list.
Line 6 prints out elements from guests list.
Line 7 uses ‘for‘ loop to generate message about plans of secret birthday party while on the secret mission to colleagues.
Result:
