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
#4
maybe I misunderstood what you want
(Nov-14-2018, 02:53 PM)wardancer84 Wrote: val = [ some comprehension magic]
print(val)
i.e. I thought you want just the values
is that ok:
print('\n'.join(['{} = {}'.format(key, value) for key, value in oprions.items()]))
in python 3.6+
print('\n'.join([f'{key} = {value}' for key, value in oprions.items()]))
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:07 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  List Comprehension Issue johnywhy 5 547 Jan-14-2024, 07:58 AM
Last Post: Pedroski55
  Dictionary in a list bashage 2 575 Dec-27-2023, 04:04 PM
Last Post: deanhystad
  filtering a list of dictionary as per given criteria jss 5 708 Dec-23-2023, 08:47 AM
Last Post: Gribouillis
  Sort a list of dictionaries by the only dictionary key Calab 1 505 Oct-27-2023, 03:03 PM
Last Post: buran
Question mypy unable to analyse types of tuple elements in a list comprehension tomciodev 1 496 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,035 May-17-2023, 09:52 PM
Last Post: rob101
  How to add list to dictionary? Kull_Khan 3 1,019 Apr-04-2023, 08:35 AM
Last Post: ClaytonMorrison
  Using list comprehension with 'yield' in function tester_V 5 1,270 Apr-02-2023, 06:31 PM
Last Post: tester_V
  list comprehension 3lnyn0 4 1,428 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,230 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