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
Brandon Pharis
1,773 PointsDictionaries challenge task string_factory
i can not figure this out. I looked at the forum and someone else had the same problem.
def string_factory(dicts, string):
strings = []
for item in dicts:
string.format(**mydicts)
strings.append(item)
return strings
it says that format() has to use mapping, not a list. im not sure what this means and tried troubleshooting online.
Jason Anello
Courses Plus Student 94,610 PointsHi Brandon,
I fixed your code for you.
This thread will show you how to post code properly: https://teamtreehouse.com/forum/posting-code-to-the-forum
Also, it's a good idea to link to the challenge you're on so anyone can review it if they need to.
2 Answers
Juan Martin
14,335 PointsHello Brandon, I've checked your code, this is what happened:
- In the for loop you have to use "for items in range(len(dicts))" to specify the number of times it will go.
- While appending, you should append "string.format(**mydicts)" using the index "item" used in the "for" loop as the index of the dictionary.
Let me show you what I mean:
def string_factory(dicts,string):
result_list = []
for item in range(len(dicts)):
result_list.append(string.format(**dicts[item]))
return result_list
By the way, to insert code, here's a forum thread about it: https://teamtreehouse.com/forum/how-to-type-code-in-the-forum
Hope this helps :)
Brandon Pharis
1,773 PointsOh okay. So it had to be specified what i was trying to append after the (**dicts). Thanks for the help and also for the link to how to type code in the forum! :)
Juan Martin
14,335 PointsYou're welcome Brandon :) ! I'm glad I could help you! Have a great day!
Chris Christensen
9,281 PointsFrustration rant. I have to be honest. I don't think that the video goes far enough in explaining packing and unpacking in a way that helps to solve this challenge. I've watched the video several times and it doesn't come close to explaining packing and unpacking in a way that helps with this challenge.
With other parts of this course rewatching videos has been helpful in understanding the material. This video should be revisited because I'm sure I'm not the only person struggling with this.
Don't get me wrong. I love the course and I've learned a lot. Just venting a bit. :/
Brandon Pharis
1,773 PointsBrandon Pharis
1,773 Pointssorry i havnt figured out how to show the code properly in a comment. Its all jumbled together