Python: function that gets n-th element of a list -
i have list of strings
['abc', 'def', 'ghij']
and want list of strings containing first letter of each string, i.e.
['a', 'd', 'g'].
i thought doing using map , function returns first element of list: my_list[0]
. how can pass map
?
thanks.
you should use list comprehension, @avasal since it's more pythonic, here's how map
:
>>> operator import itemgetter >>> l = ['abc', 'def', 'ghij'] >>> map(itemgetter(0), l) ['a', 'd', 'g']
Comments
Post a Comment