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 trial

Python Technical Interview Prep: Python Basics Basic Python Splitsville

Noor Hafiza Binti Ibrahim
Noor Hafiza Binti Ibrahim
11,712 Points

A 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,

split.py
# 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
MOD
Jeff Muday
Treehouse Moderator 28,720 Points

That 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
Noor Hafiza Binti Ibrahim
Noor Hafiza Binti Ibrahim
11,712 Points

I see. I missed an important part there. Thank you very much, I finally passed the challenge 🥳

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,441 Points

Hey 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!