This Next Part is Key


I was working on "This Next Part is Key" and I was trying to combine the commands into one line. So instead of this:

print residents['Sloth']
print residents['Burmese Python']

I wanted something a little more like this:

"print residents ['Sloth' and 'Burmese Python']

and it wouldn't work. Is this simply impossible? or is there something I am missing that would allow me to do this operation in this fashion?



Can you send a link?


Here is the section he is talking about.


I'm pretty sure there's no way to do it, but there may be. But why would you even want to? I mean, why would you want:
if you can get
And even if it is possible I'm pretty sure you can't pass with a code like that...


As far as I know the best you would be able to do is
print residents['Sloth'], residents['Burmese Python']


Oh. That makes sense. But I don't get why you'd want them on the same line...


The only thing I can think of would be if you wanted to print out a list of values from a dictionary and have them separated by commas, but even then I can't really imagine any sort of use case since the values are relatively meaningless without their keys.


I guess I was just more so looking for a shorter way to write it out. Not because it is long to write it the other way at all, just for the thought of having it ‘easier’. I suppose I also hadn’t thought about it long enough that it would be:

I was assuming it would still be written in the same format.


Unfortunately because it's only two items there isn't really a shorter way of doing it. If, however, we were dealing with three or more items, then it gets to the point where a loop would make sense.


Yeah I think I understand that better now as i’ve worked though this more. Thanks for all your help!


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.