Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Technical Interview Prep: Python Basics Basic Python Splitsville

Noor Hafiza Binti Ibrahim
Noor Hafiza Binti Ibrahim
11,616 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 26,896 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,616 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 67,464 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!