题目:

Scenario

Now that the competition gets tough it will Sort out the men from the boys .

Men are the Even numbers and Boys are the odd  


Task

Given an array/list [] of n integers , Separate The even numbers from the odds , or Separate the men from the boys  


Notes

  • Return an array/list where Even numbers come first then odds

  • Since , Men are stronger than Boys , Then Even numbers in ascending order While odds in descending .

  • Array/list size is at least *4*** .

  • Array/list numbers could be a mixture of positives , negatives .

  • Have no fear , It is guaranteed that no Zeroes will exists . 

  • Repetition of numbers in the array/list could occur , So (duplications are not included when separating).


Input >> Output Examples:

menFromBoys ({7, 3 , 14 , 17}) ==> return ({14, 17, 7, 3})

Explanation:

Since , { 14 } is the even number here , So it came first , then the odds in descending order {17 , 7 , 3} .


menFromBoys ({-94, -99 , -100 , -99 , -96 , -99 }) ==> return ({-100 , -96 , -94 , -99})

Explanation:

  • Since , { -100, -96 , -94 } is the even numbers here , So it came first in ascending order , *then** *the odds in descending order { -99 }

  • Since , (Duplications are not included when separating) , then you can see only one (-99) was appeared in the final array/list .


menFromBoys ({49 , 818 , -282 , 900 , 928 , 281 , -282 , -1 }) ==> return ({-282 , 818 , 900 , 928 , 281 , 49 , -1})

Explanation:

  • Since , {-282 , 818 , 900 , 928 } is the even numbers here , So it came first in ascending order , then the odds in descending order { 281 , 49 , -1 }

  • Since , (Duplications are not included when separating) , then you can see only one (-282) was appeared in the final array/list .

题目很长,其实大意就是:找出list中的偶数和奇数的不重复组合,偶数进行升序,奇数进行降序排列

解题办法:

def men_from_boys(arr):
return sorted([i for i in set(arr) if i%2==0]) + sorted([i for i in set(arr) if i%2!=0], reverse=True)

其他解题思路:

def men_from_boys(arr):
men = []
boys = []
for i in sorted(set(arr)):
if i % 2 == 0:
men.append(i)
else:
boys.append(i)
return men + boys[::-1]

知识点:

1、去除重复项使用set()

2、排序使用sorted(list, reverse=False)

3、奇数偶数获取

【Kata Daily 190919】Sort Out The Men From Boys(排序)的更多相关文章

  1. sort如何按指定的列排序·百家电脑学院

    sort如何按指定的列排序·百家电脑学院 sort如何按指定的(9php.com)列排序 0000            27189           41925425065f           ...

  2. js 排序:sort()方法、冒泡排序、二分法排序。

    js中的排序,这里介绍三种,sort()方法.冒泡排序.二分法排序. 1.sort方法 写法:  数组.sort(); 返回排好序的数组,如果数组里是数字,则由小到大,如果是字符串,就按照第一个字符的 ...

  3. 【Kata Daily 190929】Password Hashes(密码哈希)

    题目: When you sign up for an account somewhere, some websites do not actually store your password in ...

  4. 【Kata Daily 190909】The Supermarket Queue(超市队列)

    题目: There is a queue for the self-checkout tills at the supermarket. Your task is write a function t ...

  5. 【Kata Daily 191012】Find numbers which are divisible by given number

    题目: Complete the function which takes two arguments and returns all numbers which are divisible by t ...

  6. 【Kata Daily 191010】Grasshopper - Summation(加总)

    题目: Summation Write a program that finds the summation of every number from 1 to num. The number wil ...

  7. 【Kata Daily 190927】Counting sheep...(数绵羊)

    题目: Consider an array of sheep where some sheep may be missing from their place. We need a function ...

  8. 【Kata Daily 190924】Difference of Volumes of Cuboids(长方体的体积差)

    题目: In this simple exercise, you will create a program that will take two lists of integers, a and b ...

  9. 【Kata Daily 190923】Odder Than the Rest(找出奇数)

    题目: Create a method that takes an array/list as an input, and outputs the index at which the sole od ...

随机推荐

  1. Java知识系统回顾整理01基础05控制流程02 switch

    一.switch switch 语句相当于 if else的另一种表达方式 switch可以使用byte,short,int,char,String,enum 注: 每个表达式结束,都应该有一个bre ...

  2. python数据结构之图深度优先和广度优先实例详解

    本文实例讲述了python数据结构之图深度优先和广度优先用法.分享给大家供大家参考.具体如下: 首先有一个概念:回溯 回溯法(探索与回溯法)是一种选优搜索法,按选优条件向前搜索,以达到目标.但当探索到 ...

  3. Hadoop理论基础

    Hadoop是 Apache 旗下的一个用 java 语言实现开源软件框架,是一个开发和运行处理大规模数据的软件平台.允许使用简单的编程模型在大量计算机集群上对大型数据集进行分布式处理.   特性:扩 ...

  4. 微服务 | Spring Cloud(一):从单体SSM 到 Spring Cloud

    系列文章目录 微服务 | Spring Cloud(一):从单体SSM 到 Spring Cloud 目录 系列文章目录 前言 单体式架构 微服务架构 优点 缺点 服务发现与弹性扩展 参考 前言 在微 ...

  5. 多测师讲解接口测试 _postman(上)_高级讲师肖sir

    Postman 一.Postman介绍 Postman是一个网页调试工具,也可以调试css.html Postman的操作环境 环境:Postman Mac.Windows X32.Windows X ...

  6. python数据清洗

    盖帽法 分箱法 简单随机抽和分层抽

  7. [论文阅读]阿里DIN深度兴趣网络之总体解读

    [论文阅读]阿里DIN深度兴趣网络之总体解读 目录 [论文阅读]阿里DIN深度兴趣网络之总体解读 0x00 摘要 0x01 论文概要 1.1 概括 1.2 文章信息 1.3 核心观点 1.4 名词解释 ...

  8. Java NIO:选择器

    最近打算把Java网络编程相关的知识深入一下(IO.NIO.Socket编程.Netty) Java NIO主要需要理解缓冲区.通道.选择器三个核心概念,作为对Java I/O的补充, 以提升大批量数 ...

  9. go内建方法 new和make区别

    package mainimport ( "fmt" "reflect")func main() { // make函数 //makeSlice() // 创建 ...

  10. Linux命令获得帮助

    在Linux中获得帮助 查帮助的思路 whatis CMD mandb type CMD 如果内部:help CMD ; man bash 如果外部:CMD --help | -h 概述 获取帮助的能 ...