擅长:python、mysql、java
<p>您应该在此处使用更好的数据结构(如字典):</p>
<pre><code>Students = {
"student1": ("Allan", "Anderson"),
"student2": ("Barry", "Byars"),
"brendan": ("Brendan", "Smith"),
"sandy": ("Sandy", "Garner")
}
StudentList = [student for student in Students.values()]
print(StudentList)
</code></pre>
<p>输出</p>
<pre><code>[('Allan', 'Anderson'), ('Barry', 'Byars'), ('Brendan', 'Smith'), ('Sandy', 'Garner')]
</code></pre>
<p>这样,如果要添加另一个列表,只需在字典中添加一行,而无需更改任何逻辑:</p>
<pre><code>Students["JohnDoe"] = ("John", "Doe")
</code></pre>
<p>输出:</p>
<pre><code>[('Allan', 'Anderson'), ('Barry', 'Byars'), ('Brendan', 'Smith'), ('Sandy', 'Garner'), ('John', 'Doe')]
</code></pre>