Python Forum
Can I retrieve 2 values in a for ?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Can I retrieve 2 values in a for ?
#1
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
Reply
#2
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
Output:
key -> value_exc_vat value -> 16.67 key -> value_inc_vat value -> 17.5035 key -> valid_from value -> 2023-11-06T13:00:00Z key -> valid_to value -> 2023-11-06T13:30:00Z key -> payment_method value -> None
Kakalok likes this post
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags


Reply
#3
Absolutely fantastic, thank you for such a rapid response. Big Grin
Reply
#4
Glad I could help.
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags


Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  'soup.findAll()' help - Want to retrieve multiple attribute values MattRHope 1 17,603 Jul-29-2017, 11:35 PM
Last Post: metulburr

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020