Recent Changes - Search:

Oktatás

* Programozás 1
  + feladatsor
  + GitHub oldal

* Szkriptnyelvek
  + feladatsor
  + quick link

Teaching

* Programming 1 (BI)
  ◇ exercises
  ◇ quick link

teaching assets


Félévek

* 2024/25/2
* archívum


Linkek

* kalendárium
   - munkaszüneti napok '20
* tételsorok
* jegyzetek
* szakdolgozat / PhD
* ösztöndíjak
* certificates
* C lang.
* C++
* C#
* Clojure
* D lang.
* Java
* Nim
* Scala


[ edit | logout ]
[ sandbox | passwd ]

Remove duplicates

See also:

(1) remove duplicates
def main():
    li = [8, 8, 5, 1, 1, 1, 3, 3]

    result = sorted(set(li))

    print(result)  # [1, 3, 5, 8]
import std.stdio;
import std.algorithm; // sort(), uniq()
import std.array; // array()

void main()
{
    int[] li = [8, 8, 5, 1, 1, 1, 3, 3];

    int[] result = li.sort.uniq.array;

    writeln(result); // [1, 3, 5, 8]

    writeln(li); // [1, 1, 1, 3, 3, 5, 8, 8]
}

Notes:

  • sort() does 2 things: (1) it sorts the list in-place AND (2) it returns a range over the sorted elements
  • If you don't want to change the original list, make a copy of it: … = li.dup.sort.uniq.array;
  • uniq() only works on a sorted input (like the uniq command in Unix: cat file.txt | sort | uniq)
Cloud City

  

Blogjaim, hobbi projektjeim

* The Ubuntu Incident
* Python Adventures
* @GitHub
* heroku
* extra
* haladó Python
* YouTube listák


Debrecen | la France


[ edit ]

Edit - History - Print *** Report - Recent Changes - Search
Page last modified on 2025 June 29, 11:33