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 ]

Pop the first/last element

See also:

(1) pop the first/last element
def main():
    li = [8, 5, 1, 3]

    first = li.pop(0)
    print(first)  # 8
    print(li)  # [5, 1, 3]

    last = li.pop()
    print(last)  # 3
    print(li)  # [5, 1]
import std.stdio;
import std.range; // from here

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

    int first = li.front;
    writeln(first); // 8
    li.popFront();
    writeln(li); // [5, 1, 3]

    int last = li.back;
    writeln(last); // 3
    li.popBack();
    writeln(li); // [5, 1]
}

popFront() and popBack() do not return anything (they are procedures).

Pop an inner element

(2) pop an inner element
#!/usr/bin/env rdmd

import std.stdio;
import std.algorithm;

void main()
{
    // pop this:   v
    int[] li = [8, 5, 1, 3];

    int elem = li[1];
    writeln(elem); // 5
    li = li.remove(1);
    writeln(li); // [8, 1, 3]
}
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, 22:13