python - 从 2 个 1 维列表在 python 中创建 2 维列表
问题描述
在我的程序中,我创建了 2 个一维列表。我需要将这 2 个列表组合成一个二维列表。我不知道该怎么做。到目前为止,这是我创建 2 个列表的代码:
def main():
winners = []
year = 1903
yearlist = []
with open('WorldSeriesWinners.txt') as myfile:
for line in myfile:
line = line.rstrip('\n')
winners.append(line)
for num in range(len(winners)):
yearlist.append(year)
year += 1
print(winners)
print (yearlist)
main()
解决方案
Just add your list to new list?
foo = [winners, yearlist]
BTW: list yearlist
is completely useless as what you store there is just each winner's index + 1903.
推荐阅读
- python - 如何使用 Pandas 定位 3 个堆叠的条形图
- java - 通用接口方法的共享抽象实现:“该方法不会覆盖其超类中的方法”
- python - 从记事本++启动Python指定窗口的位置和大小
- windows - docker-compose 中的 Windows 10 绑定挂载不起作用
- machine-learning - 无法使用 Sklearn 和 Keras Wrappers 使 pipeline.fit() 工作
- fabric - 为晶圆厂 2 设置默认主机
- outlook - Outlook 加载项在打开新电子邮件时关闭
- html - 什么决定了标签辅助函数的属性顺序?
- javascript - JavaScript 错误 (Uncaught SyntaxError: Unexpected end of input) 为什么?
- extjs - 选择组合框 extjs 的默认值