Python Forum
List with "or" value?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
List with "or" value?
#5
(Jul-21-2018, 01:16 AM)WolfWayfarer Wrote: @perfringo: we're not allowed to use the calendar module, we have to do it "manually" so yeah, we're asked to invent the wheel although cars exist. I'm not against that, it's just that I really had no clue how to do it.

If it's all about not using proper tools then I would suggest to blow your teachers mind with following Monty-liner*:

year = 2014
months = sum([[[31, 30][i <= 6 and i % 2 == 0 or i > 7 and i % 2 != 0] if i / 2 != 1 else [28, 29][year % 4 == 0]] for i in range(1, 13)], [])
months value will be:

Output:
[31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
it works with leap years, so year = 2016 value will be:

Output:
[31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
* Monty is Python's evil twin and his mission is to oppose Zen of Python whenever possible and abuse Python syntax.
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply


Messages In This Thread
List with "or" value? - by WolfWayfarer - Jul-20-2018, 04:13 AM
RE: List with "or" value? - by DeaD_EyE - Jul-20-2018, 06:50 AM
RE: List with "or" value? - by perfringo - Jul-20-2018, 07:23 AM
RE: List with "or" value? - by WolfWayfarer - Jul-21-2018, 01:16 AM
RE: List with "or" value? - by perfringo - Jul-23-2018, 08:13 AM
RE: List with "or" value? - by WolfWayfarer - Jul-23-2018, 09:05 AM
RE: List with "or" value? - by perfringo - Jul-23-2018, 01:17 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020