0

I have a dictionary like this:

'id': 6, 'user_id': 1, 'approved': 0, 'is_ok': 0, 'solution': '2', 'category': '2', 'language': '2', 'hint_1': '1', 'hint_2': '2', 'hint_3': '3', 'hint_4': '4', 'hint_5': '5', 'hint_6': '6', 'hint_7': '7', 'hint_8': '8', 'hint_9': '9', 'hint_10': '2', 'hint_11': '2', 'hint_12': '2', 'hint_13': '2', 'hint_14': '2', 'hint_15': '2', 'hint_16': '2', 'hint_17': '2', 'hint_18': '2', 'hint_19': '2', 'hint_20': '2'

Is there a way to get a list of all values, where the key starts with hint_?, ? being placeholder? Thanks.

I think it could be done via a function that compares strings, but there might be a better solution!?

Marco P.
  • 13
  • 6

1 Answers1

0

Handy one-liner:

[item for key, item in dictionary.items() if key.startswith('hint_')]
Seth
  • 2,214
  • 1
  • 7
  • 21