python - How can I get all days between two days? -


I need all working days between two days.

Example:

 Wednesday - Friday = Wednesday, Thursday, Friday 3 - 5 = 3, 4, 5 Saturday - Tuesday = Saturday, Sunday, Monday, Tuesday 6 - 2 = 6 , 7, 1, 2 

I'm pretty sure to make sure there is a clever algorithm to solve it. Only the algorithms I can consider using a loop or if statement.

This should be a great way to solve. I use number 1-7 in weekdays, but 0-6 is also fine.

The best I can come up with:

  def between (d1, d2): allds = [0,1,2,3,4,5,6 , 0,1,2,3,4,5,6] # or range (7) * 2 offsets = 8 if D1 & gt; (2, 4) Between # [0,1,2,3,4] (5,2) # [5,6,0,1,2] between D2 and 1 returns allied [d1: d2 + offset ]  

  & gt; & Gt; & Gt; Def weekdays (S, E): ... for reserve [n% 7] ... ... gt; reserve (en, e + (1 if e & gt; second 8)); & Gt; & Gt; On weekdays (2, 4) [2, 3, 4] & gt; & Gt; & Gt;  

This is a bit more complex if you have to convert from real days to / from actual days.

  & gt; & Gt; & Gt; Day = 'Mars Mars Mercury Venus Saturn' split ()> gt; & Gt; & Gt; Days_1 = {n: n for n, n enumerate (day)}> gt; & Gt; & Gt; Def weekdays_between (s, e): ... s, e = days_1 [s], days_1 [E] ... returns to n [days [n% 7] returns (s, e + (1 if e & Gt; S other 8)) ... & gt; & Gt; & Gt; Days of the week_ ('Mercury', 'Venus') ['Mercury', 'Guru', 'Venus']> gt; & Gt; & Gt; ['Saturn', 'Sue'] ['Saturn', 'Sun', 'Som', 'Mangal']  

Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -