1.Find The Parity Outlier
Description:

You probably know the “like” system from Facebook and other pages. People can “like” blog posts, pictures or other items. We want to create the text that should be displayed next to such an item.

Implement a function likes :: [String] -> String, which must take in input array, containing the names of people who like an item. It must return the display text as shown in the examples:

likes [] // must be "no one likes this"
likes ["Peter"] // must be "Peter likes this"
likes ["Jacob", "Alex"] // must be "Jacob and Alex like this"
likes ["Max", "John", "Mark"] // must be "Max, John and Mark like this"
likes ["Alex", "Jacob", "Mark", "Max"] // must be "Alex, Jacob and 2 others like this"

For more than 4 names, the number in and 2 others simply increases.

My answer:

def likes(names):length=len(names)if length==0:return 'no one likes this'elif length==1:return '%s likes this' % names[0]elif length==2:return '%s and %s like this' % (names[0],names[1])elif length==3:return '%s, %s and %s like this' % (names[0],names[1],names[2])else:return '%s, %s and %d others like this' % (names[0],names[1],length-2)

good anstwer:

def likes(names):n = len(names)return {0: 'no one likes this',1: '{} likes this', 2: '{} and {} like this', 3: '{}, {} and {} like this', 4: '{}, {} and {others} others like this}[min(4, n)].format(*names[:3], others=n-2)

format通过{}和:来代替%。以后尝试用format来替代%

2.Find The Parity Outlier
Description:

You are given an array (which will have a length of at least 3, but could be very large) containing integers. The array is either entirely comprised of odd integers or entirely comprised of even integers except for a single integer N. Write a method that takes the array as an argument and returns N.

For example:

[2, 4, 0, 100, 4, 11, 2602, 36]

Should return: 11

[160, 3, 1719, 19, 11, 13, -21]

Should return: 160
我写的好蠢:

def find_it(integers,temp):if temp==1:for i in integers:if i%2==0:return ielse:for i in integers:if i%2==1:return idef find_outlier(integers):if integers[0]%2==integers[1]%2==0:return find_it(integers,1)elif integers[0]%2==integers[1]%2==1:return find_it(integers,0)else:if integers[2]%2==0:return find_it(integers,1)else:return find_it(integers, 0)

可以统计奇数和偶数的数量,返回数量为1的
x if x < y else y:如果x < y返回x,否则返回y

codewars day1相关推荐

  1. Alpha冲刺——day1

    Alpha冲刺--day1 作业链接 Alpha冲刺随笔集 github地址 站立式会议 会议安排:alpha冲刺的第一天,我们站立式会议讨论了我们接下来的安排,做出大致的规划,并针对之前的原型设计, ...

  2. python商业爬虫_商业爬虫学习笔记day1

    day1 一. HTTP 1.介绍: https://www.cnblogs.com/vamei/archive/2013/05/11/3069788.html http://blog.csdn.ne ...

  3. Codewars Vasya - Clerk--6 kyu--Python解法

    Codewars Vasya - Clerk–6 kyu–Python解法 Codewars 是一个跟LeetCode类似的结题网站. Codewars题解专栏:Codewars题解 题目地址:Tra ...

  4. 凯文·凯利:未来很美好,今天仍是Day1

    编者注:凯文·凯利(Kevin Kelly),常被称为"KK",<连线>(Wired Magazine)第一任主编:曾担任<全球评论>(Whole Eart ...

  5. WC2017 Day1

    WC2017 Day1 字符串算法 0x00 字符串的性质 字符串的周期(period):例如abcabca 周期为3 字符串的border :相同前后缀 显然如果一个长为s字符串有长度为r的bord ...

  6. noip2011提高组day1+day2解题报告

    Day1 T1铺地毯https://www.luogu.org/problem/show?pid=1003 [题目分析] 全部读入以后从最后一个往前找,找到一个矩形的范围覆盖了这个点,那这个矩形就是最 ...

  7. Codewars 开篇

    今年二月份,因为寒假在家休息了一段时间,打算干点正事打发无聊的时光.于是想刷点题找找编程的感觉,之前也刷过一些OJ题.Leetcode上的题,所以本来是计划刷一些leetcode的题,就当是为以后找工 ...

  8. NOI Day1线上同步赛梦游记

    Preface 第一次体验NOI,虽然不是正式选手,但是打打同步赛还是挺涨姿势的,也算是体验了一把. Day1很爆炸,一方面是NOI题目的难度高于自身的水平,另一方面也出现了比较大的失误,T1一个数组 ...

  9. 培训补坑(day1:最短路two-sat)

    经过12天的滚粗,终于迎来了暑期培训的结尾啦QAQ 结业考才考了90分,真是对不起孙爷(孙爷请收下我的膝盖) orz小粉兔怒D rank 1 获得小粉兔一只QAQ 由于这次12天的培训题目又比较多,算 ...

  10. Java-GUI编程实战之管理系统 Day1【项目开发流程、软件三层架构、项目需求、项目结构分析】

    视频.课件.源码[链接:https://pan.baidu.com/s/13ffqGDzH-DZib6-MFViW3Q 提取码:zjxs] Java-GUI编程实战之管理系统 Day1[项目开发流程. ...

最新文章

  1. 两张图看懂GC 日志
  2. servlet返回数据_JavaEE の Servlet - Http/Servlet - Day14 - 190507
  3. c语言函数汉诺塔不用move,C语言——汉诺塔问题(函数递归)
  4. 函数防抖 和 函数节流
  5. 介绍一个有趣的网站 - 历史上的今天
  6. 网络工程师需要具备哪些素质或专业技术
  7. Java 8:在2分钟内将智能流与数据库一起使用
  8. android 组件化_Android 组件化路由框架设计(仿Arouter)
  9. LeetCode 230. 二叉搜索树中第K小的元素(中序遍历)
  10. java第四次上机作业
  11. ionic 页面传值问题
  12. ldflags android,Android 开发手记一 NDK编程实例
  13. springboot的基础面试题
  14. opencv图像分析与处理(13)- 彩色图像处理基础:彩色模型与伪彩色图像处理
  15. video-audio
  16. 计算机网络基础学ppt,计算机网络基础学习情景.ppt
  17. WPF 加载Gif动态图片的方法
  18. 阿龙学堂-Java手机号码归属地查询
  19. 【spark】map算子n种简化写法
  20. PPT柱形统计图制作详情——小白秒变大神

热门文章

  1. Alertmanager 通知模板
  2. Ps怎么做火焰字 PS火焰字制作图文教程
  3. 群晖docker创建运行spring cloud微服务
  4. qt轻松实现不规则按钮
  5. 不规则图形面积的计算
  6. Spanning-tree fast features配置案例
  7. matlab求解整数规划问题
  8. java osgi框架_4大 Java OSGi 框架比较 (Knopflerfish, Apache Felix, Equinox, Spring DM)
  9. Django视图层模版层全面解析全网最细的教程
  10. Serverless实战——2分钟,教你用Serverless每天给女朋友自动发土味情话