[Tutor] Making big 'uns into little 'uns
crawlzone at gmail.com
Fri Sep 7 04:07:27 CEST 2012
On 09/06/2012 05:31 PM, Steven D'Aprano wrote:
> On 06/09/12 23:56, Ray Jones wrote:
>> I have a multiple 'if' expression that I need to drastically reduce in
>> size, both for readability and to keep errors from creeping in.
>> For example, I would like to have the variable 'test' point to the a
>> location 'grid[rcount-1][ccount-1]' so that everywhere I would use
>> 'grid.....', I could replace it with 'test' How would I accomplish that?
> Um, am I missing something blindingly obvious here?
> What about this?
> test = grid[rcount-1][ccount-1] # I can never think of good names...
> if test < 1:
> elif test == 1:
> do_something_different(test, 2, 3, 4)
> elif 1 < test <= 100:
> do_another_thing(test, "ham", "cheese")
> # and so on...
No, you're not missing something blindingly obvious - I was! <blush>
More information about the Tutor