在创建单词长度列表中对我不起作用吗?
str = "Python is a programming language"
str = str.split()
for char in str:
len(char)
char = words_in_list
print(list(words_in_list))
我认为输出必须像这样 [6,2,1,11,8]
答案 0 :(得分:1)
string = "Python is a programming language"
string = string.split()
my_list = []
for word in string:
my_list.append(len(word))
print(my_list)