如何拆分文本数组?

时间:2012-02-05 12:50:36

标签: python django

我有一系列答案,包括标记。

  

语法 - [“ANSWER1 | MARK1,ANSWER2 | MARK2 ...]

answers = ["Human machine interface for lab abc computer applications|3",
             "A survey of user opinion of computer system response time|4",
             "The EPS user interface management system|2",
             "System and human system engineering testing of EPS|1"]

我需要拆分它们并为每个答案提取标记。我该怎么做?

1 个答案:

答案 0 :(得分:5)

例如:

>>> [a.split("|") for a in answers]
[['Human machine interface for lab abc computer applications', '3'], 
['A survey of user opinion of computer system response time', '4'], 
['The EPS user interface management system', '2'], 
['System and human system engineering testing of EPS', '1']]