Gep*_*ada 8 python string list scramble
我正在编写一个程序,我需要在python 中搜索strings 的字母list.比如我有一个list的string就像:
l = ['foo', 'biology', 'sequence']
Run Code Online (Sandbox Code Playgroud)
我想要这样的东西:
l = ['ofo', 'lbyoogil', 'qceeenus']
Run Code Online (Sandbox Code Playgroud)
最好的方法是什么?
谢谢你的帮助!
Tim*_*ara 21
Python包含电池..
>>> from random import shuffle
>>> def shuffle_word(word):
... word = list(word)
... shuffle(word)
... return ''.join(word)
Run Code Online (Sandbox Code Playgroud)
列表理解是创建新列表的简单方法:
>>> L = ['foo', 'biology', 'sequence']
>>> [shuffle_word(word) for word in L]
['ofo', 'lbyooil', 'qceaenes']
Run Code Online (Sandbox Code Playgroud)