[Tutor] RESOLVED: Re: Is there an easily or shorter way?

Ken G. beachkidken at gmail.com
Tue Dec 16 16:17:09 CET 2014

On 12/15/2014 07:47 PM, Danny Yoo wrote:
>> Thank you but actually whatever number I get from either 1 to 28,
>> each number represent a property name such as "Reading Railroad",
>> "Judy Avenue", "Pacific Gas and Electric", etc., etc.
>> For example:
>> if x = 1 then print "Mediterranean Avenue"
>> if x = 2 then print "Baltic Avenue"
> Ah, cool!  Ok, then yes, definitely a list.  There's a sequential-ness
> here that we should take advantage of.
>     PLACES = ["Is-there-a-place-when-x-is-zero?",
>                    "Mediterranean Avenue",
>                    "Baltic Avenue",
>                    ]    # and so on ...
>     print PLACES[x]
> so that all the conditioning dissolves into a single list lookup.
> There might need to be a few more checks to make sure x is in bounds,
> but it's worth it here.
Thank you, thank you. As I think it over through the night, I had a
very faint idea of what you suggested. Again, thank.


More information about the Tutor mailing list