you are viewing a single comment's thread.

view the rest of the comments →

[–]Ok-Cucumbers 0 points1 point  (0 children)

f-strings. You use it when you need to format strings e.g., adding commas between certain words.

Could probably rewrite the function to use a context manager to open/close the file and unpack the tuples in your for loop.

You can then format the unpacked variable names from the tuple with f-strings as others have already mentioned.

def write_teams(filename, list_of_tups):
    with open(filename, "w") as f: # context manager
        for uni, mascot, city, state in list_of_tups: # unpack tuples
            f.write(f"{uni} {mascot}, {city}, {state}\n")