Izento
Izento

Reputation: 119

Changing a list to int

I'm completely stumped on how to change a list to an int.

#Creates a list which is populated by whole names and scores
    whole_names = list()
    scores = list()

    for line in lines:
        # Makes each word a seperate object
        objects = line.split(" ")
        # Joins the first and last name of every line and makes them 
          their own seperate objects
        whole_names.append(" ".join(objects[0:2]))
    # Makes the scores of every line an object
        scores.append(objects[2:3])

rect = Rectangle(Point(2, y-50), Point(scores[0],y-25))
rect.setFill("darkgreen")
rect.draw(win)

The problem is, the Point(scores[0], y-25)) wont fill because scores[0] is a list, not an int, so it technically cant be a coordinate, but the actual value of scores[0] in that list is going to be some random number, I don't know what number it will be, but it will in fact be an integer. So how do I turn scores[0] into the random integer? I've tried scores = int(scores) but that didn't work at all.

Upvotes: 2

Views: 121

Answers (2)

aIKid
aIKid

Reputation: 28252

Assuming scores[0] is something like ['10']:

Point(int(scores[0][0]), y-25)

However, this not the right solution. To make it better, change this line:

scores.append(objects[2:3])

Which return a sequence, to this:

scores.append(objects[2])

Which returns the item itself. With this, you'll only have to convert it to integer straight away:

Point(int(scores[0]), y-25)

Hope this helps!

Upvotes: 2

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 798556

    scores.append(objects[2:3])

This line gives you a 1-element sequence, which is probably not what you want. Index instead of slicing.

    scores.append(objects[2])

Upvotes: 2

Related Questions