0

We can do something like below in C:

struct teams {
char team_name[100];
int team_point[100];
}
struct teams teams1[100];

We get array of struct in this way, is it somehow possible in Python? Thanks

leppie
118k18 gold badges201 silver badges300 bronze badges
asked Nov 7, 2012 at 7:36
3
  • 1
    You don't need to do that in Python (it's dynamic!), but you can do it if you want to - what's your use case? Commented Nov 7, 2012 at 8:35
  • Why would you have an array of points within the struct? Commented Nov 7, 2012 at 8:37
  • It's not an array of structs, however, it's a struct of arrays. Commented Nov 18, 2012 at 23:35

1 Answer 1

3
class Team(object):
 def __init__(self, name, points):
 self.name = name
 self.points = points
teams = []
teams.append(Team('Chicago Bulls', [85, 75, 93, 10]))

Since Python is dynamic, nothing prevents you from assigning arbitrary values to object properties (object instances behave mostly like namespaces), but lacking a pedantic compiler screaming about type mismatches has some advantages.

answered Nov 7, 2012 at 8:40
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.