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 trialfaisalrustom
1,300 PointsHow to solve this challenge?
Can someone please explain how to solve this challenge?
3 Answers
Nathan Tallack
22,160 PointsWhat you are going to want to do is have a for loop that runs over the dictionry and in that for loop use a switch to work out which category to append the dictionary value to.
In pseudocode, it would look something like this.
for key, value in dictionary {
switch key {
case "XXX", "YYY": list1.append(value)
case "AAA", "BBB": list2.append(value)
default: otherList.append(value)
}
}
Here we are using a "switch" to quickly do something that could otherwise be done in a much more time consuming if then else if type manner. :)
faisalrustom
1,300 PointsI tried this but it's not working
for (key, value) in world {
switch key {
case "BEL" : europeanCapitals.append(world[0]) }
}
Nathan Tallack
22,160 PointsClose. Try something like this.
for (key, value) in world {
switch key {
case "BEL", "LIE", "BER": europeanCapitals.append(value)
:)
faisalrustom
1,300 Pointsthanks it worked <3