Python Forum

Full Version: Splitting a list help
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have been coding python 3 using repl.it, and I have this code. To make everything work I had it print to make sure it worked. For some reason, Stats wont split as part of health.

Stats = [5, 5, 5, 5, 5],
Head = 'Leather Cap',
Torso = 'Leather Vambrace',
Arms = 'Leather Shoulder Pads',
LeftHand = 'Iron Longsword',
RightHand = 'Wooden Buckler',
Legs = 'Leather Pants',
Feet = 'Leather Boots',
PlayerOneStats = {}
PlayerOneHealthCap = Stats[0]
print(PlayerOneHealthCap)
Help please!

Moderator: Added code tags for you this time. Please use in future.
Quote:Stats wont split as part of health
stats is a list. It is already split. More info..
What I mean is that when it prints the health part it still print the entire list of 5s without taking just the first one or multiplying it. How can I remedy this?
list[0] will return the first element of the list
>>> stats = [1,2,3,4,5,6,7,8]
>>> stats[0]
1
Quote:Stats = [5, 5, 5, 5, 5],
Head = 'Leather Cap',
Torso = 'Leather Vambrace',
Arms = 'Leather Shoulder Pads',
LeftHand = 'Iron Longsword',
RightHand = 'Wooden Buckler',
Legs = 'Leather Pants',
Feet = 'Leather Boots',
What is up with the commas after each line?
You have an extra comma at the end of  Stats = [5, 5, 5, 5, 5], so Python thinks Stats is a one-element tuple, whose first element is [5, 5, 5, 5, 5]. So Stats[0] is [5, 5, 5, 5, 5].... Remove the comma and it should work as expected.
Doh