wordlist = ['cat','dog','rabbit']
letterlist = [ ]
要列出所有字符的所有单词,我们可以这样做: letterlist = [word[i] for word in wordlist for i in range(len(word))]
['c', 'a', 't', 'd', 'o', 'g', 'r', 'a', 'b', 'b', '
我有一个看起来像alist = ['4', '1.6', 'na', '2e-6', '42']的python列表。如果我想从这个删除引号,并使它看起来像[4, 1.6, na, 2e-6, 42],通常我使用下面的代码: alist = [float(x) if type(x) is str else None for x in alist]
但是这一次,因为我有串'na'在列表中的元素之一