Get first word of all strings in lists

前端 未结 4 1443
粉色の甜心
粉色の甜心 2021-01-22 13:37

I have a CSV file which I\'m reading in like below. I need to get the first word of all the strings. I know how to get first letter but I\'m not sure how I can get words.

4条回答
  •  不要未来只要你来
    2021-01-22 13:52

    l = [
        ['diffuse systemic sclerosis', 'back', 'public on july 15 2008'],
        ['diffuse systemic sclerosis', 'forearm', 'public on may 9 2014']
        ]
    d = lambda o: [a.split().pop(0) for a in o]
    r = lambda a,b: d(a) + d(b)
    print "\n".join(set(reduce(r, l)))
    >>> 
    public
    forearm
    diffuse
    back
    

提交回复
热议问题