Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialSergio Andrés Herrera Velásquez
Courses Plus Student 23,765 PointsUh oh, I didn't get the correct value returned. It should have been '55555' for the zip. Instead, it was ' 55555'
what am I missing here? Bummer: Uh oh, I didn't get the correct value returned. It should have been '
# enter your code here
def splitsville(address):
split_address=address.split(',')
street,city,state,zip_code=split_address
dictionary={'street':street,
'city':city,
'state':state,
'zip_code':zip_code,}
return dictionary
3 Answers
Steven Parker
231,275 PointsIf you look carefully, you'll notice that the "wrong" answer shown in the message has a space in it, but it is expecting the correct value to be just the digits.
So to properly separate your values, the split token needs to be defined as a comma and a space.
Andy Hughes
8,479 PointsHey Sergio,
So your split needs to allow for space around the comma. You'll see that there is a space after each one so include that.
Your function won't be able to understand:
street,city,state,zip_code=split_address
as essentially, you're just creating a new variable. Also, your dictionary syntax is not quite right and you're being asked to 'return' the dictionary not put it inside of a variable.
So your split ( taking account of my comments above ), should produce a list of elements from an address. You could then create a variable that contains your keys i.e.
keys = 'street', 'city', 'state', 'zip_code',
Now you have a split address and your keys separately so they need to be joined. To do this, return your dictionary using the zip function to join 'keys' to 'split_address'. The zip() function produces a list, so you then just need to convert that into a dictionary as follows:
return dict(zip(keys, split_address))
Hope that made sense and helps :)
Sergio Andrés Herrera Velásquez
Courses Plus Student 23,765 PointsHi,Andy Hughes.
Thank you for your reply, while your answer was very complete, I feel like it was overcomplicating the process and the answer, as to the street,city,state,zip_code=split_address
` part, it was just meant to unpack the values from the split, and then using the variables as values, rather than fixed values.
I believe in code being explicit rather than implicit( having to guess or look at more complex options like zip or dict which would need more digging into if anyone would look at the code for the 1st time)
Thank you again
Andy Hughes
8,479 PointsActually looking at this again, I realise I had changed your code before realising the space after the comma. If you just change that, the code technically works.
I guess i was trying to use less code and play with concepts shown from other videos. But i totally take your point; if someone doesn't know zip(), it's confusing.
Glad you got it sorted. Happy coding. :)
Sergio Andrés Herrera Velásquez
Courses Plus Student 23,765 PointsSergio Andrés Herrera Velásquez
Courses Plus Student 23,765 PointsSteven Parker Thank you, it indeed helped me pass the challenge, somehow I missed it, hahaha I really appreciate it