checkio the most frequent weekdays
2016-03-25 11:38
357 查看
Input: Year as an int.
Output: The list of most frequent days sorted by the order of days in week (from Monday to Sunday).
找出一年中最多的那个星期几。
这个好。后来想到了,只要看第一周和最后一周就可以了,有相交的weekday就取相交的那几天。没有就取或。callendar模块这里写链接内容
Output: The list of most frequent days sorted by the order of days in week (from Monday to Sunday).
找出一年中最多的那个星期几。
from datetime import * from datetime import timedelta def most_frequent_days(year): a={"Monday":0,"Tuesday":0,"Wednesday":0,"Thursday":0,"Friday":0 ,"Saturday":0,"Sunday":0} e={"Monday":0,"Tuesday":1,"Wednesday":2,"Thursday":3,"Friday":4 ,"Saturday":5,"Sunday":6} b={0:"Monday",1:"Tuesday",2:"Wednesday",3:"Thursday",4:"Friday",5:"Saturday",6:"Sunday"} now = date(year,1,1) while(now.year==year): a[b[now.weekday()]]+=1 now = now + timedelta(days=1) c=sorted(a.items(),key=lambda asd:asd[1],reverse =True) d=[] while(c[-1][1] != c[0][1]): c.pop() for i in range(len(c)): d.append(c[i][0]) return sorted(d,key=lambda x:e[x])
这个好。后来想到了,只要看第一周和最后一周就可以了,有相交的weekday就取相交的那几天。没有就取或。callendar模块这里写链接内容
from datetime import datetime from calendar import day_name def most_frequent_days(year): first = set(range(datetime(year, 1, 1).weekday(), 7)) last = set(range(datetime(year, 12, 31).isoweekday())) return [day_name[day] for day in sorted((first & last) or (first | last))]
相关文章推荐
- CActiveXUI的一个Bug
- duilib 自绘标题 最大化图标显示bug ----WindowImplBase的bug
- iOS应用开发中的文字选中操作控件UITextView用法讲解
- iOS自定义UITableCell自定义分割线消失问题
- Android UI 小结
- Dynamic Web Module 3.0 requires Java 1.6 or newer
- UITextView详解
- LeetCode 225 Implement Stack using Queues
- CDuiString的bug
- 设计模式:建造者模式(Builder)
- 设计模式:建造者模式(Builder)
- 关于UICollectionViewCell的问题
- Java day09 StringBuffer与StringBuilder
- Interger声明的在-128 ~ 127之间值比较为true
- 关于button — 点击变换背景图片
- ${pageContext.request.contextPath}的作用
- X5的UI部分和传统Web页面开发的差异
- IOS开发UI篇--使用CAShapeLayer实现复杂的View的遮罩效果
- unigui中TUniDBEdit的OnEndDrag问题
- iOS UILabel设置行间距和字间距并计算高度