问题描述
我想在字典列表中添加一个id键,其中每个id代表枚举的嵌套字典。
当前词典列表:
current_list_d = [{'id': 0,'name': 'Paco','age': 18} #all id's are 0
{'id': 0,'name': 'John','age': 20}
{'id': 0,'name': 'Claire','age': 22}]
所需的输出:
output_list_d = [{'id': 1,'age': 18} #id's are counted/enumerated
{'id': 2,'age': 20}
{'id': 3,'age': 22}]
我的代码:
for d in current_list_d:
d["id"]+=1
解决方法
您可以对enumerate
使用一个简单的for循环,并在字典中就位更新rev
键。
c(rev(cumprod(rev(v[-1]))),1)
#[1] 120 60 20 5 1
,
您可以使用变量。
private GUIStyle currentStyle = null;
void OnGUI()
{
InitStyles();
GUI.Box( new Rect( 0,100,100 ),"Hello",currentStyle );
}
private void InitStyles()
{
if( currentStyle == null )
{
currentStyle = new GUIStyle( GUI.skin.box );
currentStyle.normal.background = MakeTex( 2,2,new Color( 0f,1f,0f,0.5f ) );
}
}
private Texture2D MakeTex( int width,int height,Color col )
{
Color[] pix = new Color[width * height];
for( int i = 0; i < pix.Length; ++i )
{
pix[ i ] = col;
}
Texture2D result = new Texture2D( width,height );
result.SetPixels( pix );
result.Apply();
return result;
}