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 trialNoor Hafiza Binti Ibrahim
11,712 PointsA typo? Any better ways to solve the code challenge?
All i get is: Bummer: Uh oh, I didn't get the correct value returned. It should have been '55555' for the zip. Instead,
# enter your code here
def splitsville(address):
address = address.split(",")
keys = 'street', 'city', 'state', 'zip_code'
address_dict = dict(zip(keys, address))
return address_dict
2 Answers
Jeff Muday
Treehouse Moderator 28,722 PointsThat is a clever solution. Good work!
Unfortunately, it does require stripping the parts of the extraneous spaces. There are quite a few ways to do this, I suggest a simple approach below. (alternatively, you could also use a "list comprehension" after the split.)
Good luck with your Python studies!
def splitsville(address):
address = address.split(",")
keys = 'street', 'city', 'state', 'zip_code'
address_dict = dict(zip(keys, address))
for k, v in address_dict.items():
address_dict[k] = v.strip()
return address_dict
Chris Freeman
Treehouse Moderator 68,457 PointsHey Noor Hafiza Binti Ibrahim, cheers for a novel approach.
Your code works with only a minor adjustment. Split on comma-space using split(“, “)
. This will pass the challenge!
Noor Hafiza Binti Ibrahim
11,712 PointsThanks 👍 for the great tips. 😁
Noor Hafiza Binti Ibrahim
11,712 PointsNoor Hafiza Binti Ibrahim
11,712 PointsI see. I missed an important part there. Thank you very much, I finally passed the challenge 🥳