python定义空列表it_如何在Python中创建多个(但单个)空列表?

本文探讨了如何在Python中动态地生成多个空列表,而不是手动修改字母来创建。通过尝试不同的方法,如使用列表推导式和字典,最终提出使用字典来简化过程,如`fields = {key: [] for key in 'ABCD'}`,允许按需引用或遍历每个列表。
摘要由CSDN通过智能技术生成

I wrote a script that at one point generates a bunch of empty lists applying a code with the structure:

A,B,C,D=[],[],[],[]

which produces the output:

A=[]

B=[]

C=[]

D=[]

The way it is right now, I have to manually modify the letters each time I use a different dataset as an input. I want to be able to automatize that.

I thought about doing this:

FieldList=[A,B,C,D]

bracket=[]

[[0]for field in FieldList]

for field in FieldList:

bracket=bracket+["[]"]

FieldList=bracket

Here I was trying to replicate " A,B,C,D=[],[],[],[]", but evidently that's not how it works.

I also tried:

FieldList=[A,B,C,D]

bracket=[]

[[0]for field in FieldList]

for field in FieldList:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值