Can someone help and kindly advise how Can I get specific values from this dictionary (Using list comprehension) and
items_list = {'a': 3, 'b':6, 'c': 'short', 'h': 'example', 'p': 77}
So, the output needs to be:
9, 36, 5929
Short, Example
(Python):
items_list = {'a': 3, 'b': 6, 'c': 'short', 'h': 'example', 'p': 77}
lst = [v ** 2 if isinstance(v, (int, float)) else v.capitalize() for v in
items_list.values()]
print(lst)
output:
[9, 36, 'Short', 'Example', 5929]
The exact output that you showed can not be produced using single list comprehension, because the iteration is in order.