convert list to string?

后端 未结 1 1324
春和景丽
春和景丽 2021-01-27 21:19

I was wondering if there was a way to convert my List into a String.

Example: Is there a way to convert MyList = [\'a\', \'b\', \'c\', \'d\', \'e\'] to

1条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-27 22:21

    >>> MyList = ['a', 'b', 'c', 'd', 'e']
    >>> ''.join(MyList)
    
    'abcde'
    

    The solution to your other question

    >>> MyList = ['a', 'b', 'c', 'd', 'e']
    
    >>> all(letter in MyList for letter in 'bad')
    True
    
    >>> all(letter in MyList for letter in 'test')
    False
    

    0 讨论(0)
提交回复
热议问题