I have a list of 127716 lists. Characters, numerics ect. This length will vary with other lists I will use later. The values are in order so that they are in similar groups of 1435 lists. They in turn will form 10-11 groups of 5-12 groups of lists. I want to be able to separate the groups and access them by variables taken from the the third and forth lists, i.e. l[2] and l[3] of each group. They will look like this. Example: x(1,1), x(1,2),...,x(1,8), x(2,1), x(2,2),...,x(2,12),......x(11,1), ...,x(11,6)
I use python 3.6.3 and visual studio code I am obviously a beginner I have looked thru all the tutorials I can find and tried to search *, but can find no questions that answer my problem. I am trying to rewrite a basic program I wrote 35 years ago, or maybe 40. I can create a dictionary of a group, but only one without being able to use variables in the dictionary names. Is there a way in python to name a list, dictionary, string, tuple or other data type using variables?
我有一个127716列表的列表。人物,数字等。此长度将随后我将使用的其他列表而变化。这些值是按顺序排列的,因此它们属于1435个列表的类似组。他们反过来将形成10-11组5-12组列表。我希望能够将这些组分开并通过从第三和第四列表中取得的变量来访问它们,即每组的l [2]和l [3]。它们看起来像这样。示例:x(1,1),x(1,2),...,x(1,8),x(2,1),x(2,2),...,x(2,12) ),...... x(11,1),...,x(11,6)我使用python 3.6.3和visual studio代码我显然是初学者我通过所有可以找到的教程看了并试图搜索*,但没有找到回答我的问题的问题。我正在尝试重写一个35年前写的基本程序,或者也许是40个。我可以创建一个组的字典,但只有一个不能在字典名中使用变量。有没有办法在python中使用变量命名列表,字典,字符串,元组或其他数据类型?
I hope this is the way to respond to queries.
我希望这是回应查询的方式。
The third and forth lists, i.e. l[2] and l[3] of each group are identifying numbers. They are integers, from 1-12 usually, and they make the best identifiers of the 1435 unit groups. They are unique to each group and can be used to separate and identify the groups. That is why I want to use them as variables to name whatever data type I can find.
第三和第四列表,即每组的l [2]和l [3]是识别号码。它们是整数,通常为1-12,它们是1435个单位组的最佳标识符。它们对每个组都是唯一的,可用于分隔和识别组。这就是为什么我想将它们用作变量来命名我能找到的任何数据类型。
here is a sample of the list ['"EMD"', '"20170820"', '1', '1', '', '870', '"D"', '', '"N"', '"BUN"', '"Ch15k"', '15000', '', '', '45.79', '""', '"H"', '""', '""', '"EMD"', '1', '"QH"', '9', '', '', '0', '0', '0', '0', '', '22', '1', '1', '0', '"LORENZOJMARQUEZ"', ................................... '"EMD"', '"20170820"', '1', '2',.......... ['"EMD"', '"20170820"', '1', '3',................
这是一个列表的样本['“EMD”','“20170820”','1','1','','870',''D“','','”N“', '“BUN”',''Ch15k'','15000','','','45 .79','''','“H”','“'','”“'','”EMD “','1','”QH“','9','','','0','0','0','0','','22','1', '1','0','“LORENZOJMARQUEZ”',...................................' “EMD”','“20170820”','1','2',.......... ['“EMD”','“20170820”','1','3', ................
....................................['"EMD"', '"20170820"', '11', '8']
.................................... ['“EMD”','“20170820”',' 11','8']
d = {}
a = {}
i,j = 0,0
for x in range(0,len(L)-1):
a={(l[i+2],l[i+3]):{'trail':l[0+i], 'date':l[i+1], 'number': l[i+2], 'position':l[i+3],........
# I break the group down again to about 76 lists per each 1435 group here and try to start a
# dictionary but need to create dictionaries within a dictionary using my identifiers as the
# dictionary name.
z = (int(l[i+2]),int(l[i+3]))
d = [z] = {(str(a))}
i=i + 1435
1 个解决方案
#1
0
This works. First part of code was by Mike Muller and I figured out the second part from his comments. This is a way in python to name a dictionary using variables. step = 1435 d = {} for start in range(0, len(l), step): end = start + step part = l[start:end] d[tuple(part[2:4])] = part uu=1 vari = {} for x in range(1,12):
for y in range(1,15): if (str(x),str(y)) in d: vari[uu] = d[str(x),str(y)][50] print(('key ',x,y),('value ',vari[uu]),('counter ',uu))
#check results uu=uu+1
print('out of loop check ', vari[87]) # check results
这很有效。代码的第一部分是Mike Muller,我从他的评论中找到了第二部分。这是python中使用变量命名字典的一种方法。 step = 1435 d = {} for range in range(0,len(l),step):end = start + step part = l [start:end] d [tuple(part [2:4])] = part uu = 1 vari = {}对于范围内的x(1,12):对于范围内的y(1,15):if(str(x),str(y))in d:vari [uu] = d [str( x),str(y)] [50] print(('key',x,y),('value',vari [uu]),('counter',uu))#check结果uu = uu + 1 print('out of loop check',vari [87])#检查结果
#1
0
This works. First part of code was by Mike Muller and I figured out the second part from his comments. This is a way in python to name a dictionary using variables. step = 1435 d = {} for start in range(0, len(l), step): end = start + step part = l[start:end] d[tuple(part[2:4])] = part uu=1 vari = {} for x in range(1,12):
for y in range(1,15): if (str(x),str(y)) in d: vari[uu] = d[str(x),str(y)][50] print(('key ',x,y),('value ',vari[uu]),('counter ',uu))
#check results uu=uu+1
print('out of loop check ', vari[87]) # check results
这很有效。代码的第一部分是Mike Muller,我从他的评论中找到了第二部分。这是python中使用变量命名字典的一种方法。 step = 1435 d = {} for range in range(0,len(l),step):end = start + step part = l [start:end] d [tuple(part [2:4])] = part uu = 1 vari = {}对于范围内的x(1,12):对于范围内的y(1,15):if(str(x),str(y))in d:vari [uu] = d [str( x),str(y)] [50] print(('key',x,y),('value',vari [uu]),('counter',uu))#check结果uu = uu + 1 print('out of loop check',vari [87])#检查结果