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

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

python - cx_oracle unable to find Oracle Client -