I have a function that I'm trying to loop through, with the purpose of amending those variables with a ", "
after them.
def create_merge(address, city, state_province, country, postal_code, contact, state):
for key in locals().keys():
for value in locals().values():
print(key, value)
This ...kind of works, but not really. While it gives me a proper readout of all values in that def, it only shows state
for the key. I get why, because I'm looping through all values in the first key, before it moves to the second.
What I'd like to have is a loop that would produce, say:
address 123 My Address
city
state_province Illinois
country USA
postal_code 12345
contact McGruff
state Illinois
And this, clearly just first lists the keys, then the values. How do I do one key and one value at a time?
for key in locals().keys():
print (key)
for value in locals().values():
print (value)
...print (key, key.values())
doesn't work.
Nor
for key in locals().keys():
print (key, locals().values())
I think I'm getting close, but just can't get it! Thanks for any suggestions/advice.
Final note: I need to do this in a way where I can see if the value
is NOT empty, and if not empty, amend the value with ", "
before the function continues.