Python列表列表作为字典值

时间:2018-12-14 06:17:44

标签: python python-3.x

我有一个列表列表,如下所示:

servers = [['serv1','10.10.10.10','00','onehost'],['serv2','10.10.10.20','01','twohost']]

我需要一本类似以下的字典

Appdict = {'App': ['serv1','10.10.10.10','00','onehost'],['serv2','10.10.10.20','01','twohost']}

我已经尝试通过压缩2个列表来尝试zip方法,但是在前端解析数据有困难。 我也尝试了以下方法:

for i in servers:
   Appdict.update(servers[i])

创建字典的最佳方法是什么?谢谢您的宝贵时间!

1 个答案:

答案 0 :(得分:0)

如果我理解正确,那么您想要这样做:

TArray<FColor> ColorData;
TArray<FColor> *ptrColorData
//Where TArray is essentially a vector. FColor is a struct with members (R,G,B,A)

//ColorData is initialised somewhere and we set the ptrColorData to the address
ptrColorData = &ColorData;

//Somewhere down the line we have a long loop whereby we do
ColorData[i].B = somedata[i];
ColorData[i].G = somedata[i+1];
ColorData[i].R = somedata[i+3];

//somedata is updated per tick, asigning ColorData per tick as well slows it down.
// I wish to be able to do something on the lines of this

ptrColorData[i].B = &somedata[i];
ptrColorData[i].G = &somedata[i+1];
ptrColorData[i].R = &somedata[i+3];

// this is only called once to initialize. Because the memory address
//is unchanging and somedata changes by functions on its own it means when
// I tell my unreal engine to update a texture by passing (*ptrColorData)
// to a function it automatically has the new data when that function is
// next called.

这将产生:

Appdict  = {}
Appdict['App'] = servers