Extract values from dict [closed]Calling a function of a module by using its name (a string)How to merge two dictionaries in a single expression?Sort a Map<Key, Value> by valuesHow to return multiple values from a function?How to print without newline or space?Convert bytes to a string?How do I sort a dictionary by value?Why can't Python parse this JSON data?Extract file name from path, no matter what the os/path formatWhy is “1000000000000000 in range(1000000000000001)” so fast in Python 3?

Do people actually use the word "kaputt" in conversation?

Is this saw blade faulty?

Why can't I get pgrep output right to variable on bash script?

Center page as a whole without centering each element individually

Did I make a mistake by ccing email to boss to others?

Why is "la Gestapo" feminine?

Is there any common country to visit for persons holding UK and Schengen visas?

Error in master's thesis, I do not know what to do

Not hide and seek

Started in 1987 vs. Starting in 1987

What do the positive and negative (+/-) transmit and receive pins mean on Ethernet cables?

Toggle window scroll bar

1 John in Luther’s Bibel

If the Dominion rule using their Jem'Hadar troops, why is their life expectancy so low?

Checking @@ROWCOUNT failing

New Order #2: Turn My Way

Why doesn't Gödel's incompleteness theorem apply to false statements?

Trouble reading roman numeral notation with flats

Calculate Pi using Monte Carlo

Exposing a company lying about themselves in a tightly knit industry (videogames) : Is my career at risk on the long run?

Put the phone down / Put down the phone

Travelling in US for more than 90 days

When is the exact date for EOL of Ubuntu 14.04 LTS?

Do native speakers use "ultima" and "proxima" frequently in spoken English?



Extract values from dict [closed]


Calling a function of a module by using its name (a string)How to merge two dictionaries in a single expression?Sort a Map<Key, Value> by valuesHow to return multiple values from a function?How to print without newline or space?Convert bytes to a string?How do I sort a dictionary by value?Why can't Python parse this JSON data?Extract file name from path, no matter what the os/path formatWhy is “1000000000000000 in range(1000000000000001)” so fast in Python 3?













-1















I have a problem that is to extract all values from two dictionaries:



'Art': ['SKU': 'BS0000504000', 'SKU': 'BS0000504010', 'SKU': 'BS0000504500', 'SKU': 'BS0000505000',....]


How I can extract all values of SKU dynamical?



Another example that I like to know what is the best approach to extract values.



 'Art1': 'SKU': 'BS0000504000', 'Art2': 'SKU': 'BS000050401', 'Art3': 'SKU': 'BS0000504500', 'Art4': 'SKU': 'BS0000505000',....]


In this case I use this print(result['Art1']['SKU']) to extract the SKU from Art1, but I like to extract all value from Art1, Art2, ..., Artn.



Thanks










share|improve this question















closed as off-topic by js1568, xlm, TofuBeer, Sid S, Alexandre Dion Mar 7 at 22:42


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example." – js1568, xlm, Sid S, Alexandre Dion
If this question can be reworded to fit the rules in the help center, please edit the question.
















  • Hey there, I can see that you're new to Stack Overflow. Might you have any code samples for what you've tried so far, perhaps using a for loop or a forEach?

    – Hannele
    Mar 7 at 20:05















-1















I have a problem that is to extract all values from two dictionaries:



'Art': ['SKU': 'BS0000504000', 'SKU': 'BS0000504010', 'SKU': 'BS0000504500', 'SKU': 'BS0000505000',....]


How I can extract all values of SKU dynamical?



Another example that I like to know what is the best approach to extract values.



 'Art1': 'SKU': 'BS0000504000', 'Art2': 'SKU': 'BS000050401', 'Art3': 'SKU': 'BS0000504500', 'Art4': 'SKU': 'BS0000505000',....]


In this case I use this print(result['Art1']['SKU']) to extract the SKU from Art1, but I like to extract all value from Art1, Art2, ..., Artn.



Thanks










share|improve this question















closed as off-topic by js1568, xlm, TofuBeer, Sid S, Alexandre Dion Mar 7 at 22:42


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example." – js1568, xlm, Sid S, Alexandre Dion
If this question can be reworded to fit the rules in the help center, please edit the question.
















  • Hey there, I can see that you're new to Stack Overflow. Might you have any code samples for what you've tried so far, perhaps using a for loop or a forEach?

    – Hannele
    Mar 7 at 20:05













-1












-1








-1








I have a problem that is to extract all values from two dictionaries:



'Art': ['SKU': 'BS0000504000', 'SKU': 'BS0000504010', 'SKU': 'BS0000504500', 'SKU': 'BS0000505000',....]


How I can extract all values of SKU dynamical?



Another example that I like to know what is the best approach to extract values.



 'Art1': 'SKU': 'BS0000504000', 'Art2': 'SKU': 'BS000050401', 'Art3': 'SKU': 'BS0000504500', 'Art4': 'SKU': 'BS0000505000',....]


In this case I use this print(result['Art1']['SKU']) to extract the SKU from Art1, but I like to extract all value from Art1, Art2, ..., Artn.



Thanks










share|improve this question
















I have a problem that is to extract all values from two dictionaries:



'Art': ['SKU': 'BS0000504000', 'SKU': 'BS0000504010', 'SKU': 'BS0000504500', 'SKU': 'BS0000505000',....]


How I can extract all values of SKU dynamical?



Another example that I like to know what is the best approach to extract values.



 'Art1': 'SKU': 'BS0000504000', 'Art2': 'SKU': 'BS000050401', 'Art3': 'SKU': 'BS0000504500', 'Art4': 'SKU': 'BS0000505000',....]


In this case I use this print(result['Art1']['SKU']) to extract the SKU from Art1, but I like to extract all value from Art1, Art2, ..., Artn.



Thanks







python json python-3.x dictionary






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 7 at 0:54









blhsing

39.4k41743




39.4k41743










asked Mar 7 at 0:47









Andre SantosAndre Santos

42




42




closed as off-topic by js1568, xlm, TofuBeer, Sid S, Alexandre Dion Mar 7 at 22:42


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example." – js1568, xlm, Sid S, Alexandre Dion
If this question can be reworded to fit the rules in the help center, please edit the question.







closed as off-topic by js1568, xlm, TofuBeer, Sid S, Alexandre Dion Mar 7 at 22:42


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example." – js1568, xlm, Sid S, Alexandre Dion
If this question can be reworded to fit the rules in the help center, please edit the question.












  • Hey there, I can see that you're new to Stack Overflow. Might you have any code samples for what you've tried so far, perhaps using a for loop or a forEach?

    – Hannele
    Mar 7 at 20:05

















  • Hey there, I can see that you're new to Stack Overflow. Might you have any code samples for what you've tried so far, perhaps using a for loop or a forEach?

    – Hannele
    Mar 7 at 20:05
















Hey there, I can see that you're new to Stack Overflow. Might you have any code samples for what you've tried so far, perhaps using a for loop or a forEach?

– Hannele
Mar 7 at 20:05





Hey there, I can see that you're new to Stack Overflow. Might you have any code samples for what you've tried so far, perhaps using a for loop or a forEach?

– Hannele
Mar 7 at 20:05












1 Answer
1






active

oldest

votes


















1














Assuming your dict is stored as variable d, the following list comprehension will extract the SKU values in the first format:



[s['SKU'] for l in d.values() for s in l]


and the following list comprehension will extract the SKU values in the second format:



[s['SKU'] for s in d.values()]





share|improve this answer























  • I have something like this?... import requests import time url = "siteurl.test" data = requests.get(url) d = data.json() t0 = time.time() [s['SKU'] for s in d.values()] print("Total time " + str(time.time() - t0) + " sec")

    – Andre Santos
    Mar 7 at 1:05


















1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














Assuming your dict is stored as variable d, the following list comprehension will extract the SKU values in the first format:



[s['SKU'] for l in d.values() for s in l]


and the following list comprehension will extract the SKU values in the second format:



[s['SKU'] for s in d.values()]





share|improve this answer























  • I have something like this?... import requests import time url = "siteurl.test" data = requests.get(url) d = data.json() t0 = time.time() [s['SKU'] for s in d.values()] print("Total time " + str(time.time() - t0) + " sec")

    – Andre Santos
    Mar 7 at 1:05
















1














Assuming your dict is stored as variable d, the following list comprehension will extract the SKU values in the first format:



[s['SKU'] for l in d.values() for s in l]


and the following list comprehension will extract the SKU values in the second format:



[s['SKU'] for s in d.values()]





share|improve this answer























  • I have something like this?... import requests import time url = "siteurl.test" data = requests.get(url) d = data.json() t0 = time.time() [s['SKU'] for s in d.values()] print("Total time " + str(time.time() - t0) + " sec")

    – Andre Santos
    Mar 7 at 1:05














1












1








1







Assuming your dict is stored as variable d, the following list comprehension will extract the SKU values in the first format:



[s['SKU'] for l in d.values() for s in l]


and the following list comprehension will extract the SKU values in the second format:



[s['SKU'] for s in d.values()]





share|improve this answer













Assuming your dict is stored as variable d, the following list comprehension will extract the SKU values in the first format:



[s['SKU'] for l in d.values() for s in l]


and the following list comprehension will extract the SKU values in the second format:



[s['SKU'] for s in d.values()]






share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 7 at 0:52









blhsingblhsing

39.4k41743




39.4k41743












  • I have something like this?... import requests import time url = "siteurl.test" data = requests.get(url) d = data.json() t0 = time.time() [s['SKU'] for s in d.values()] print("Total time " + str(time.time() - t0) + " sec")

    – Andre Santos
    Mar 7 at 1:05


















  • I have something like this?... import requests import time url = "siteurl.test" data = requests.get(url) d = data.json() t0 = time.time() [s['SKU'] for s in d.values()] print("Total time " + str(time.time() - t0) + " sec")

    – Andre Santos
    Mar 7 at 1:05

















I have something like this?... import requests import time url = "siteurl.test" data = requests.get(url) d = data.json() t0 = time.time() [s['SKU'] for s in d.values()] print("Total time " + str(time.time() - t0) + " sec")

– Andre Santos
Mar 7 at 1:05






I have something like this?... import requests import time url = "siteurl.test" data = requests.get(url) d = data.json() t0 = time.time() [s['SKU'] for s in d.values()] print("Total time " + str(time.time() - t0) + " sec")

– Andre Santos
Mar 7 at 1:05






Popular posts from this blog

AWS Lex not identifying response if by a variable The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) The Ask Question Wizard is Live! Data science time! April 2019 and salary with experienceEnforcing custom enumeration in AWS LEX for slot valuesHow to give response based on user response in Amazon Lex?Intercepting AWS Lambda Response to a AWS Lex QueryLex chat bot error: Reached second execution of fulfillment lambda on the same utteranceamazon lex showing invalid responseLambda response send back to Lex slot?Response card in Amazon lexAmazon Lex - Lambda response return HTML to botHow can I solve 424 (Failed Dependency) (python) obtained from Amazon lex?

Алба-Юлія

Захаров Федір Захарович