下面有几种做法,  其中3之简洁令人惊讶.

1,

>>> t = [1, 2, 3, 1, 2, 5, 6, 7, 8]
>>> t
[1, 2, 3, 1, 2, 5, 6, 7, 8]
>>> list(set(t))
[1, 2, 3, 5, 6, 7, 8]
>>> s = [1, 2, 3]
>>> list(set(t) - set(s))
[8, 5, 6, 7]

2,

def f7(seq):
seen = set()
seen_add = seen.add
return [x for x in seq if not (x in seen or seen_add(x))]

3,

myList = sorted(set(myList))

4,

for i in mylist:
if i not in newlist:
newlist.append(i)

python: delete the duplicates in a list的更多相关文章

  1. python delete数据

    #!/usr/bin/env python # -*- coding:utf-8 -*- # @Time : 2017/11/24 0:27 # @Author : lijunjiang # @Fil ...

  2. [Leetcode][Python]26: Remove Duplicates from Sorted Array

    # -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 26: Remove Duplicates from Sorted Array ...

  3. [LeetCode]题解(python):083 - Remove Duplicates from Sorted List

    题目来源 https://leetcode.com/problems/remove-duplicates-from-sorted-list/ Given a sorted linked list, d ...

  4. 【LeetCode】83. Remove Duplicates from Sorted List 解题报告(C++&Java&Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 判断相邻节点是否相等 使用set 使用列表 递归 日 ...

  5. [leetcode]Remove Duplicates from Sorted List @ Python

    原题地址:https://oj.leetcode.com/problems/remove-duplicates-from-sorted-list/ 题意: Given a sorted linked ...

  6. leetcode 【 Remove Duplicates from Sorted List 】 python 实现

    题目: Given a sorted linked list, delete all duplicates such that each element appear only once. For e ...

  7. 力扣—Remove Duplicates from Sorted List(删除排序链表中的重复元素)python实现

    题目描述: 中文: 给定一个排序链表,删除所有重复的元素,使得每个元素只出现一次. 示例 1: 输入: 1->1->2输出: 1->2 示例 2: 输入: 1->1->2 ...

  8. [LeetCode] 83. Remove Duplicates from Sorted List_Easy tag: Linked List

    Given a sorted linked list, delete all duplicates such that each element appear only once. Example 1 ...

  9. [leetcode] 13. Remove Duplicates from Sorted List

    这个题目其实不难的,主要是我C++的水平太差了,链表那里绊了好久,但是又不像用python,所以还是强行上了. 题目如下: Given a sorted linked list, delete all ...

随机推荐

  1. java代码实现递归

    think in java 书中使用递归分析 代码如下: public class Snake implements Cloneable { private Snake next; private c ...

  2. CSS布局框架 960GS

    1.960GS 特点 小巧简单,功能单一(仅仅做排版的工作,其他东西靠自己.)(三个文件:reset.css,960.css,font.css) 界面宽960px,适合目前主流1/2以上显示器都满屏宽 ...

  3. python----tkinterm模块

    python tkinter学习——布局   目录 一.pack() 二.grid() 三.place() 四.Frame() 正文 布局 一.pack() pack()有以下几个常用属性: side ...

  4. ansible入门二(Ansible常见模块介绍)

    本节内容: ansible命令基础 常见模块举例 一.ansible命令基础 语法: ansible <host-pattern> [-f forks] [-m module_name] ...

  5. A网页高度随B内容而自然变化兼容各种浏览器

    今天是星期一,昨天又没有睡好,眼睛干干的,还有点痛疼,于是不想干啥.但是心里又不觉得过意不去,浪费时间呀,考虑再三把自己前面实现的一个东西发了上来.算是今天的功劳,没有过多的文字描述,纯粹是贴图片和代 ...

  6. kvm虚拟机克隆注意点

    1.硬盘空间会受第一次分配硬盘是的max capacity(最大容量) 限制,如果额外添加一块硬盘,会多出一个img文件,克隆这种虚拟机,两个img文件会都克隆下来,如果不重新命名会在原先img文件后 ...

  7. vue 可编辑表格组件

    <template> <div class="table"> <table border="1px" v-dragform> ...

  8. LeetCode OJ:H-Index(H指数)

    Given an array of citations (each citation is a non-negative integer) of a researcher, write a funct ...

  9. Django中构造响应对象的方式

    1 HttpResponse 可以使用django.http.HttpResponse来构造响应对象. HttpResponse(content=响应体, content_type=响应体数据类型, ...

  10. 剑指offer--42.孩子们的游戏(圆圈中最后剩下的数)

    约瑟夫环,用链表,队列,总之模拟过程 ----------------------------------------------------------------- 时间限制:1秒 空间限制:32 ...