Quantcast
Channel: Create a list of default objects of a class in Python? - Stack Overflow
Browsing latest articles
Browse All 4 View Live

Answer by Padraic Cunningham for Create a list of default objects of a class...

[node() for _ in range(100)]And as I said in my comment:class node(object): def __init__(self, children=None): if children is None: children = [] self.children = childrenIf you used def __init__(self,...

View Article



Answer by arshajii for Create a list of default objects of a class in Python?

You can use a list comprehension:nodes = [node() for _ in range(100)]Python doesn't have a concept of "arrays" per se, but it has lists which are a higher-level structure. Lists can be indexed just...

View Article

Answer by Roger Fan for Create a list of default objects of a class in Python?

Using a list comprehension:nodes = [node() for _ in range(100)]

View Article

Create a list of default objects of a class in Python?

I have define a class in Pythonclass node(object): def __init__(self, children = []): self.children = childrenI would like to create a list or array of default objects of class node. For example,...

View Article
Browsing latest articles
Browse All 4 View Live




Latest Images