我在字典里面有列表:
Number_of_lists=3 #user sets this value, can be any positive integer
My_list={}
for j in range(1,Number_of_lists+1):
My_list[j]=[(x,y,z)]
Run Code Online (Sandbox Code Playgroud)
这Number_of_lists是用户设置的变量.如果事先不知道用户设置的值,我想最终得到所有字典列表的合并列表.例如,如果Number_of_lists=3和相应的列表是My_list[1]=[(1,2,3)],My_list[2]=[(4,5,6)],My_list[3]=[(7,8,9)]结果将是:
All_my_lists=My_list[1]+My_list[2]+My_list[3]
Run Code Online (Sandbox Code Playgroud)
哪里:
All_my_lists=[(1,2,3),(4,5,6),(7,8,9)].
所以我要做的就是尽可能自动执行上述过程:
Number_of_lists=n #where n can be any positive integer
我有点迷失到现在尝试使用迭代器添加列表并始终失败.我是一个蟒蛇初学者,这是我的一个爱好,所以如果你回答请解释你的答案中的一切我正在做这个学习,我不是要求你做我的功课:)
@codebox(看下面的评论)正确地指出My_List,我的代码中显示的实际上是字典而不是列表.如果您使用任何代码,请小心.
我有这个代码包含一个按钮bbutton,当按下该按钮时执行该movetext功能:
from pylab import *
from matplotlib.widgets import RectangleSelector
from matplotlib.widgets import Button
import numpy as np
import matplotlib.pylab as plt
fig = plt.figure()
ax = fig.add_subplot(111)
delta = 0.025
x = np.arange(-3.0, 3.0, delta)
y = np.arange(-2.0, 2.0, delta)
X, Y = np.meshgrid(x, y)
Z1 = bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0)
Z2 = bivariate_normal(X, Y, 1.5, 0.5, 1, 1)
Z = (Z1 - Z2) * 10
plt.contourf(X, Y, Z)
text1=plt.text(0, 0, 'ghghg',color='black',fontsize=14)
plt.text(1, 1, …Run Code Online (Sandbox Code Playgroud) 我有这个代码:
from pylab import *
from mpl_toolkits.axes_grid.anchored_artists import AnchoredText
import numpy as np
import matplotlib.pylab as plt
fig = plt.figure()
ax = fig.add_subplot(111)
ann = AnchoredText('If you zoom in or out, i stay here\nbut can you update this text?',
prop=dict(size=8), frameon=True,
loc=2,
)
ann.patch.set_boxstyle("round,pad=0.,rounding_size=0.2")
ax.add_artist(ann)
delta = 0.025
x = np.arange(-3.0, 3.0, delta)
y = np.arange(-2.0, 2.0, delta)
X, Y = np.meshgrid(x, y)
Z1 = bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0)
Z2 = bivariate_normal(X, Y, 1.5, 0.5, 1, 1)
Z …Run Code Online (Sandbox Code Playgroud) 我们有一个内部有一些数学函数的类
class MyObjects(object):
q=1 #could be any number
def f(x,y):
return q*y+x #could be any mathematical function
Run Code Online (Sandbox Code Playgroud)
比方说,我们要创建100个指定像新的对象object_1,object_2... object_100 这个类的,他们都必须有一个变量q定义,但对每个对象的定义q_1,q_2...... q_100但我们希望每一个对象被创建递增时间q的价值if q=1:
q_1=q+1
q_2=q_1+1等等.正如之前显示的所有对象必须使用命名为每个对象类的类的F(X,Y)的功能f_1,f_2... f_100.生成的对象的数量将由用户设置input(),这就是我想自动执行此过程的原因,通过在代码中添加类似于100个对象的"手动"来做这非常麻烦.那么我可以自动化这个程序吗?Python begginer,monty python退伍军人lol.如果您能以更精确的方式对其进行重新编辑,请随意编辑该问题.
python ×4
matplotlib ×2
automation ×1
class ×1
dictionary ×1
increment ×1
iterator ×1
list ×1
merge ×1
methods ×1
object ×1
plot ×1
visible ×1