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
dmitriy ignatiev
Python Web Development Techdegree Student 1,789 Pointsmake a dict from a list
Hi, could you explain how i could make a dict from a list if a have a code below:
The problem is that i do not understand why when i print new dict it is appear like only key ['Numbers'] with only one value (5). My purpose is to arrange new_dict like
{['Numbers': 1, 'Numbers': 2, 'Numbers': 3, 'Numbers': 4, 'Numbers':5}.
Now it looks like only {'Numbers': 5}
new_dict = {'Numbers': [1,2,3,4,5]}
new_dict_list = []
for i in new_dict['Numbers']:
new_dict_list.append(i)
for item in new_dict['Numbers']:
print(item)
new_string = "Hi, I'm {Numbers}!"
print(new_dict_list)
for each in new_dict_list:
new_dict['Numbers'] = each
print(new_dict)
1 Answer
Jason Anello
Courses Plus Student 94,610 PointsHi Dmitriy,
The keys in a dictionary have to be unique. It looks like you're trying to create a dictionary with 5 items and the keys are all the same.
Jason Anello
Courses Plus Student 94,610 PointsJason Anello
Courses Plus Student 94,610 Pointsfixed code formatting