Solve a Debate
danb_83 at yahoo.com
Sat Feb 16 05:48:31 CET 2008
On Feb 15, 10:24 am, nexes <nexes... at gmail.com> wrote:
> Alright so me and my friend are having argument.
> Ok the problem we had been asked a while back, to do a programming
> exercise (in college)
> That would tell you how many days there are in a month given a
> specific month.
> Ok I did my like this (just pseudo):
> If month = 1 or 3 or etc ....
> noDays = 31
> Elseif month = 4 or 6 etc ....
> noDays = 30
> noDays = 29
> (we didn't have to take into account a leap year)
> He declared an array and assigned the number of days in a month to its
> own element in an array. Now
> I realise that in this example it would not make a difference in terms
> of efficiency, but it is my belief that if
> there is more data that needed to be assigned(i.e. a couple megs of
> data) it would be simpler (and more efficient) to
> do a compare rather then assigning all that data to an array, since
> you are only going to be using 1 value and the rest
> of the data in the array is useless.
> What are everyone else's thoughts on this?
days_in_month = lambda m: m - 2 and 30 + bool(1 << m & 5546) or 28
More information about the Python-list