In PHP I use the array_column() function a lot as it allows me to retrieve values from a specific column inside an array returned themselves in a nice array, for example, using this array:
$users = [
[
'id' => 1,
'name' => 'Peter'
],
[
'id' => 2,
'name' => 'Paul'
],
[
'id' => 3,
'name' => 'John'
]
];
Doing array_column($users, 'name')
will return:
Array
(
[0] => Peter
[1] => Paul
[2] => John
)
Since transitioning to Python I still haven't found a built in function that I can use to do the same thing on a list
of dict
s for example.
Does such a function exist and if not, what is the best way to achieve this?