oop - How can I use a list[customClass] as type with @dataclass in Python 3.7.x - Stack Overflow
How to declare an array or a list in a Python @dataclass? - Stack Overflow
Uniquefy list of dataclass
python 3.x - dictionary get method for list of dataclass objects - find dataclass with specific variable value in list of dataclasses - Stack Overflow
I have a nested dataclass as thus:
@dataclass()
class oeFile(object):
@dataclass
class contentParticle:
identifier ='p'
material = 0
index = 0
layer = 0xff
color = 0xffffffff
xPos = 0.0
yPos = 0.0
xVel = 0.0
yVel = 0.0
xOrg = 0.0
yOrg = 0.0
angle = 0.0
angVel = 0.0
pressure = 0
content = ''
particle: contentParticle = contentParticle()
contentOeFile = oeFile()
How can I set it up so that I can run something like this? Making a new instance of oeFile, or can I make an array something like particleData = oeFile.particle[1000]?
random spaghetti pseudocode roughly envisioning what I'm hoping for
while i <= len(particleData):
(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o) = particleData[i]
i+=1
where a to o would be fed from a separate iterator pulling those values from a list, perhaps as an object that returns those values.
Yes I've been told pandas does database stuff easily but this is a programming exercise for me.
I have a list of dataclass instances that i want to uniquefy. So i want to remove all duplicates while preserving order.
[3,1,1,4,5,6,6,3] -> [3,1,4,5,6]
I have two options.
Do list(dict.fromkeys(my_list)) which is O(N) but requires me to make the dataclass unsafe_hash=True (all of its attributes are hashable but the class is mutable).
Or write the O(N2) function that works also on unhashable types.
At the moment i am torn between which way to go.