Non-unique Elements

You are given a non-empty list of integers (X). For this task, you should return a list consisting of only the non-unique elements in this list. To do so you will need to remove all unique elements (elements which are contained in a given list only once). When solving this task, do not change the order of the list. Example: [1, 2, 3, 1, 3] 1 and 3 non-unique elements and result will be [1, 3, 1, 3].

题目大义:将数组中唯一的元素清除

还是C语言的思想,直接粗暴,首先是遍历求出唯一的元素,再使用数组的remove方法

 1 def checkio(data):
2
3 only = []
4
5 for each in data:
6 count = 0
7 for other in data:
8 if each == other:
9 count += 1
10
11 if count == 1:
12 only.append(each)
13
14 for each in only:
15 data.remove(each)
16
17 return data

当然我们有更高级的方法list = [x for x in data if x.count > 1],简单明了,使用了数组的另一种构造方法,使用了数组count方法

1 def checkio(data):
2 list = [x for x in data if data.count(x) > 1]
3 return list

新技能get

Non-unique Elements的更多相关文章

  1. Ruby: Count unique elements and their occurences in an array

    Is there a method in Ruby that takes an array, and counts all unique elements and their occurrences ...

  2. [LeetCode] Top K Frequent Elements 前K个高频元素

    Given a non-empty array of integers, return the k most frequent elements. For example,Given [1,1,1,2 ...

  3. (Collection)347. Top K Frequent Elements

    Given a non-empty array of integers, return the k most frequent elements. For example,Given [1,1,1,2 ...

  4. Leetcode 347. Top K Frequent Elements

    Given a non-empty array of integers, return the k most frequent elements. For example,Given [1,1,1,2 ...

  5. 347. Top K Frequent Elements

    Given a non-empty array of integers, return the k most frequent elements. For example,Given [1,1,1,2 ...

  6. [LeetCode] 347. Top K Frequent Elements 解题思路 - Java

    Given a non-empty array of integers, return the k most frequent elements. For example,Given [1,1,1,2 ...

  7. [Swift]LeetCode347. 前K个高频元素 | Top K Frequent Elements

    Given a non-empty array of integers, return the k most frequent elements. Example 1: Input: nums = [ ...

  8. C#版(打败99.28%的提交) - Leetcode 347. Top K Frequent Elements - 题解

    版权声明: 本文为博主Bravo Yeung(知乎UserName同名)的原创文章,欲转载请先私信获博主允许,转载时请附上网址 http://blog.csdn.net/lzuacm. C#版 - L ...

  9. 347. Top K Frequent Elements 最常用的k个元素

    [抄题]: Given a non-empty array of integers, return the k most frequent elements. For example,Given [1 ...

随机推荐

  1. Linux企业级项目实践之网络爬虫(19)——epoll接口

    由于要实现爬虫程序的快速抓取,显然如果采用阻塞型的I/O方式,那么系统可能很长时间都处在等待内核响应的状态中,这样爬虫程序将大大地降低效率.然而,如果采用非阻塞I/O,那么就要一直调用应用进程,反复对 ...

  2. oracle数据库 ORA-12560: 协议适配器错误

    ORA-12560:  协议适配器错误 造成ORA-12560: TNS: 协议适配器错误的问题的原因有三个: 1.监听服务没有起起来.windows平台个一如下操作:开始---程序---管理工具-- ...

  3. MySql 查询表字段数

    MySql 查询表字段数 SELECT COUNT(*) FROM information_schema.columns WHERE table_schema='test_cases' AND tab ...

  4. iOS 消息推送原理

    一.消息推送原理: 在实现消息推送之前先提及几个于推送相关概念,如下图: 1. Provider:就是为指定IOS设备应用程序提供Push的服务器,(如果IOS设备的应用程序是客户端的话,那么Prov ...

  5. 使用PLSql连接Oracle时报错ORA-12541: TNS: 无监听程序

    非常多时候为了优化我们的启动项把oracle的服务禁止了.但是重新启动启动之后使用PLSQL登陆oracle时会出现无监听程序,这说明我们有一些服务没有启动.我们先查看一下oracle的服务是否启动, ...

  6. Linux编程环境介绍(1) -- linux的历史

    1. linux是什么? "Hello everybody out there using minix——I'm doing a (free) operating system"  ...

  7. Android-它们的定义Dialog

    Android-它们的定义Dialog 2014年4月27日 星期天 天气晴朗 心情平静 本篇博文来分享一个也是开发中常常须要用到的功能-自己定义对话框,这里我用到了Android中的图形资源shap ...

  8. 老漏洞easy击:CVE-2012 0158占顶!

    watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvaXF1c2hp/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/d ...

  9. 学习selenium所须要具备的技术

    学习selenium所须要具备的知识或技术 1.selenium进行的自己主动化測试是基于ui层面的,所以html,css,javascript基本上是不可缺少的,至于javascript,有非常多的 ...

  10. 编译U-boot时,make[1]: *** 没有规则可以创建mkimage.o”

    执行完make smdk2440_config 对Uboot重行编译怎么会出现这样的错误 make[1]: Entering directory `/home/win/S3-ARM/Part4/ubo ...