Can I retrieve 2 values in a for ? - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Can I retrieve 2 values in a for ? (/thread-41071.html) |
Can I retrieve 2 values in a for ? - Kakalok - Nov-06-2023 I have a list of values im looping through with an for x, and this is the x value {'value_exc_vat': 16.67, 'value_inc_vat': 17.5035, 'valid_from': '2023-11-06T13:00:00Z', 'valid_to': '2023-11-06T13:30:00Z', 'payment_method': None} I then run a for y in x and get the following value_exc_vat value_inc_vat valid_from valid_to payment_method Which is fine, but what I also want to do is get the numeric and text values e.g. for 'value_exc_vat' 16.67 and 'valid_from' 2023-11-06T13:00:00Z Im certain its easy, but its totally alluding me. Many thanks in advance RE: Can I retrieve 2 values in a for ? - menator01 - Nov-06-2023 Please use the bbtags for posting code. To answer the question, that is a dict you can do mydict = {'value_exc_vat': 16.67, 'value_inc_vat': 17.5035, 'valid_from': '2023-11-06T13:00:00Z', 'valid_to': '2023-11-06T13:30:00Z', 'payment_method': None} for key, value in mydict.items(): print(f'key -> {key} value -> {value}')output
RE: Can I retrieve 2 values in a for ? - Kakalok - Nov-06-2023 Absolutely fantastic, thank you for such a rapid response. RE: Can I retrieve 2 values in a for ? - menator01 - Nov-06-2023 Glad I could help. |