以下是一个示例代码,它定义了一个函数 string_list_to_list_of_lists
,该函数接收一个字符串列表作为参数,并返回一个列表的列表:
def string_list_to_list_of_lists(string_list):
result = []
for string in string_list:
result.append(list(string))
return result
# 示例用法
strings = ["abc", "def", "ghi"]
result = string_list_to_list_of_lists(strings)
print(result)
输出结果:
[['a', 'b', 'c'], ['d', 'e', 'f'], ['g', 'h', 'i']]
在这个示例中,我们遍历给定的字符串列表 string_list
,对每个字符串调用 list()
函数,将其转换为一个字符列表,并将结果添加到 result
列表中。最后,我们返回 result
列表,它包含了每个字符串的字符列表作为子列表。