I have objects stored in a list named lst in python. I need to build only one attribute of objects as a graph.
import numpy as np import matplotlib.pyplot as plt class Particle(object): def __init__(self, value = 0, weight = 0): self.value = value self.weight = weight lst = [] for x in range(0,10): lst.append(Particle(value=np.random.random_integers(10), weight = 1))
I tried this and it works, but I think this is not a very "pythonic" way:
temp = [] #any better idea? for x in range(0,len(lst)): temp.append(l[x].value) plt.plot(temp, 'ro')
what do you suggest, how to use it in a more pythonic way? Thanks you
user3053231
source share