我有一个这样的字符串列表:
List["String"] =["I am xyz", "My name is xyz", "myself xyz", "people call me xyz"]
我想将字符串拆分成这样的两列:
List["list"] = ["I am", "My name is", "myself", "people call me"]
List["Name"] = ["xyz","xyz","xyz","xyz"]
答案 0 :(得分:2)
这是您要去的地方吗?但这显然不是答案,因为您在输入中没有给我们极端的情况:)
>>> x = ["I am xyz", "My name is xyz", "myself xyz", "people call me xyz"]
>>> d = {}
>>> d['list'] = [' '.join(y.split()[:-1]) for y in x]
>>> d['name'] = [y.split()[-1] for y in x]
>>> d
{'list': ['I am', 'My name is', 'myself', 'people call me'], 'name': ['xyz', 'xyz', 'xyz', 'xyz']}