Python equivalent for PHP's implode?

后端 未结 2 1545
一个人的身影
一个人的身影 2021-02-01 00:17

Is there an equivalent for PHP\'s implode in Python? I\'ve read in and split up a set of delimited words, and now I want to sort them out in random orders and print the words ou

2条回答
  •  有刺的猬
    2021-02-01 00:28

    Use the strings join-method.

    print ' '.join(['word1', 'word2', 'word3'])
    

    You can join any iterable (not only the list used here) and of course you can use any string (not only ' ') as the delimiter.

    If you want a random order like you said in your question use shuffle.

提交回复
热议问题