1

So in some code I am writing, I have a list of objects. I also have a second list of objects, but these objects actually take the first list as a parameter(object-inception!).

Anyways, for both cases(If I can figure out how the first works, the same method may work for the second as well), I need to be able to address the data stored within a particular object after addressing that particular object's index.

Here is some Pseudo code for essentially what I would like to do.

class Object():
    def __init__(self, fruit)
        self.fruit = fruit
ObjectList = [Object("apple"), Object("banana"), Object("orange")]
newList = []
for i in ObjectList:
    newList.append(ObjectList[i].fruit)

Likewise, if I were to pass this list of objects(we will call it a list of object A) as a parameter into another object(object B), and then made a list of those objects(as as many layers as you would like to go, honestly!), I imagine that I could use the same method to extract object A list out of each object B within the object B list, and then extract the desired data out of each object A from the object A list.

For me personally, this is one of the most advanced programs I have written, and since I am new to Python I could be doing it entirely wrong. Any help or suggestions will be well taken!

0

1 Answer 1

1

In a simpler example, but solving the same issue, I actually managed to find the answer. This is just so anyone coming across this will know where to find the answer they need.

How do i access and object attribute inside a list of objects given certain index?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.