0

I have dict with below data.

{'Night': {'time': '22:00:00', 'setPoint': 140}, 'Day': {'time': '08:00:00', 'setPoint': 139}, 'Morning': {'time': '06:00:00', 'setPoint': 110}, 'Evening': {'time': '18:00:00', 'setPoint': 130}}

I want a list which contains only time Sample output:

['22:00:00','08:00:00','06:00:00','18:00:00']
Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685

2 Answers2

0

Try this:

result = [subdict['time'] for _, subdict in dic.items()]

print(result)

Produces the following output:

['22:00:00', '08:00:00', '06:00:00', '18:00:00']
DocDriven
  • 3,726
  • 6
  • 24
  • 53
0

You can use the .values() method of a dictionary:

>>> d={'Night': {'time': '22:00:00', 'setPoint': 140}, 'Day': {'time': '08:00:00', 'setPoint': 139}, 'Morning': {'time': '06:00:00', 'setPoint': 110}, 'Evening': {'time': '18:00:00', 'setPoint': 130}}
>>> [v['time'] for v in d.values()]
['22:00:00', '08:00:00', '06:00:00', '18:00:00']
rassar
  • 5,412
  • 3
  • 25
  • 41