my_dict = { 1: 11, 2: 12, 3: 13 }
If I want to work on the list of keys from my_dict there appear to be (at least) three ways to do this in Python >3.5 (i.e. on or after PEP 448)
List Comprehension:
[key for key in my_dict]
[1, 2, 3]
Unpacking:
[*my_dict]
[1, 2, 3]
Constructing a list from the view of the keys:
list(my_dict.keys())
[1, 2, 3]
Are these three methods interchangeable?
I think
[key for key in my_dict]is the most 'Pythonic',[*my_dict]is the most terse, andlist(my_dict.keys())is the most readable.
Are there any technical reasons for choosing between these?