我有两个列表如下:
List("key1", "key2")
List("val1", "val2")
我试图让它变成类似JSON的格式:
[{"key1":"val1"},{"key2","val2"}]
现在,这就是我正在使用的:
val output = List(attrKeys.zip(attrValues).toMap)
但它给了我这个:
[{"key1":"val1","key2":"val2"}]
如何将其添加到单独的地图对象列表中?
答案 0 :(得分:1)
import matplotlib.pyplot as plt
import numpy as np
def generateData(goal):
x=[_ for _ in range(20)]
y=[10+np.random.exponential()*5 for _ in range(100)]
return x,y
def drawHistogram(data,nBins):
plt.figure()
plt.hist(diffs,nBins)
sweep=np.linspace(10,20,4)
for goal in sweep:
for gw2 in sweep:
diffs=[]
for i in range(10):
data=generateData(goal)
diffs.append(goal-np.mean(data[1]))
#generate plot
plt.figure(1)
clr=(abs(np.mean(diffs))/goal,0,0)
plt.plot([goal], [gw2], marker="s", mew='1', ms='35', color=clr)
drawHistogram(diffs,5) ##Comment this line out to see what the final graph should look like
plt.draw()
plt.show()