我有一个元素列表,其文本如下所示:
aSampleElementText = "Vraj Shroff\nIndia"
我现在想要两个列表,第一个列表的元素是“Vraj Shroff”,第二个列表的元素是“India”。你知道吗
我看了其他关于分割线和分割线的帖子。然而,我下面的代码并没有给我预期的结果。你知道吗
输出:
"V",
"r"
所需输出:
"Vraj Shroff",
"India"
我的代码:
personalName = "Something" #first list
personalTitle = "Something" #second list
for i in range(len(names)-1)
#names is a list of elements (example above)
#it is len - 1 becuase I don't want to do this to the first element of the list
i += 1
temp = names[i].text
temp.splitlines()
personName.append(temp[0])
personTitle.append(temp[1])
输出:
这就是你要找的吗?你知道吗
名称是一个字符串。names[I]是与字符串中的索引相对应的字符。因此你得到了这种输出。你知道吗
像这样做
x将是包含元素的列表。你知道吗
相关问题 更多 >
编程相关推荐