Python Forum
dictionary: print key/value with list(dict) comprehension
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
dictionary: print key/value with list(dict) comprehension
#2
print(list(options.values()))

That said,
your code can be simplified to
options = {"attr1":"val1","attr2":"val2"}
 
for key, value in options.items():
    print('{} = {}'.format(key, value))
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Messages In This Thread
RE: dictionary: print key/value with list(dict) comprehension - by buran - Nov-14-2018, 03:00 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  List Comprehension Issue johnywhy 5 546 Jan-14-2024, 07:58 AM
Last Post: Pedroski55
  Dictionary in a list bashage 2 569 Dec-27-2023, 04:04 PM
Last Post: deanhystad
  filtering a list of dictionary as per given criteria jss 5 699 Dec-23-2023, 08:47 AM
Last Post: Gribouillis
  Sort a list of dictionaries by the only dictionary key Calab 1 504 Oct-27-2023, 03:03 PM
Last Post: buran
Question mypy unable to analyse types of tuple elements in a list comprehension tomciodev 1 493 Oct-17-2023, 09:46 AM
Last Post: tomciodev
  How do you get Python to print just one value in a list? 357mag 3 1,032 May-17-2023, 09:52 PM
Last Post: rob101
  How to add list to dictionary? Kull_Khan 3 1,018 Apr-04-2023, 08:35 AM
Last Post: ClaytonMorrison
  Using list comprehension with 'yield' in function tester_V 5 1,264 Apr-02-2023, 06:31 PM
Last Post: tester_V
  list comprehension 3lnyn0 4 1,426 Jul-12-2022, 09:49 AM
Last Post: DeaD_EyE
  Membership test for an element in a list that is a dict value for a particular key? Mark17 2 1,229 Jul-01-2022, 10:52 PM
Last Post: Pedroski55

Forum Jump:

User Panel Messages

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