1
连接含有空值字符串,去空
words_list = "".join([i for i in strings if i != ' '])
2
生成随机整数列表
import random
lis = [random.randint(1,20) for i in range(10)]
3
生成随机整数二维列表
lis = [ [random.randint(1,10) for i in range(3)] for i in range(3)]
4
寻找列表中字符串最长公共前缀
*序列解包
strs = ['flower', 'flow', 'flight']
def longestCommonPrefix(strs) -> str:
s = ''
for i in zip(*strs):
if len(set(i)) == 1:
s += i[0]
else:
break
return s
5
对列表中的元素计数,当然也可以list.count(i)
for num