How do I turn a list of lists of words into a sentence string?

前端 未结 4 1557
南旧
南旧 2021-02-07 00:17

I have this list

[[\'obytay\'], [\'ikeslay\'], [\'ishay\'], [\'artway\']]

where I need it to look like

obytay ikeslay ishay ar         


        
4条回答
  •  暖寄归人
    2021-02-07 01:13

    It is a list of strings. So, you need to chain the list of strings, with chain.from_iterable like this

    from itertools import chain
    print " ".join(chain.from_iterable(strings))
    # obytay ikeslay ishay artway
    

    It will be efficient if we first convert the chained iterable to a list, like this

    print " ".join(list(chain.from_iterable(strings)))
    

提交回复
热议问题