This Next Part is Key


#1



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?

Thanks!


#2

Can you send a link?


#3

Here is the section he is talking about.
https://www.codecademy.com/en/courses/python-beginner-en-pwmb1/2/1?curriculum_id=4f89dab3d788890003000096


#4

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:
104
106105
if you can get
104
106
105
And even if it is possible I'm pretty sure you can't pass with a code like that...


#5

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


#6

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


#7

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.


#8

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:
104
105106
107

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


#9

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.


#10

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


#11

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