Used to get the elements in the array with the specified index

from operator import itemgetter
itemgetter(1, 3, 5)('ABCDEFG') output:
('B', 'D', 'F')


Used to slice a list , It is also the element that gets the specified index

a = slice(0,10,2)
b = list(range(10))
itemgetter(a)(b) output:
[0, 2, 4, 6, 8]
[0, 2, 4, 6, 8]
[0, 2, 4, 6, 8]

and_ amount to a & b, To find the intersection of two sets

Can unite reduce Realize the calculation of the intersection of multiple sets

from functools import reduce
from operator import and_
print(reduce(and_, [{1,2,3},{2,3,4},{3,4,5},{1,3,5}])) output:


or_ amount to a | b, To find the intersection of two sets

Can unite reduce Realize the calculation of union of multiple sets

from functools import reduce
from operator import or_
print(reduce(or_, [{1,2,3},{2,3,4},{3,4,5},{1,3,5}])) output:
{1, 2, 3, 4, 5}


【386】operator Of itemgetter、slice、and_、or_ More articles about

  1. operator Of itemgetter and attrgetter

    I was giving you a list When sorting , Vaguely think of a grammar sugar can replace lambda function , Used to obtain list in dict Of key, In order of key. This grammar sugar is seldom used , I can't remember . Check out today python mark ...

  2. python Of operator.itemgetter('click') Used to define get 'click' Function of term

    python See article for the order of Here are import operator modular operat ...

  3. operator.itemgetter() Dictionary list sort

    ## Dictionary list sort students = [ {"name": "Stanley", "age": 22, "score" ...

  4. 【Python】operator Module brief introduction

    A brief introduction to several commonly used functions , For others, please refer to the documentation . operator.concat(a, b) **operator.__concat__(a, b)** about a.b Sequence , return a + b( List merge ) -- ...

  5. Python And operator library

    operator Library common methods Function Syntax add(a+b) a + b concat(seq1,seq2) seq1 + seq2 contains(seq, obj) obj in ...

  6. Python modular :operator Brief introduction

    Python Official document address : Operator The function provided can be used to compare ...

  7. operator Module and functools modular

    operator modular In functional programming , It is often necessary to use arithmetic operators as functions . for example , Don't use Recursively compute factorials . Summation can use sum function , But quadrature doesn't have such a function . We can use reduce function (5.2.1 ...

  8. operator Module common method introduction

    operator.concat(a, b) about a.b Sequence , return  a + b( List merge ) --------------------------------- operator.countOf(a, ...

  9. Elegant python - Multi condition sorting and itemgetter Application

    I used to use as Write a lot of code to sort , Learn from python Sorting often requires only one line , Amazing , Then to python Have a strong interest in . Before, when making the football scoreboard, we need to use multi condition ranking , If the integral is the same , According to the goal difference , Polyphase ...

Random recommendation

  1. Java Common implementations of timed tasks

    Java There are several common ways to realize the timing task of : 1)Timer 2)ScheduledThreadPoolExecutor 3)Spring In the integration Cron Quartz Next, we will introduce the specific implementation methods of these categories in turn ...


    RAM: It can be understood from the literal meaning ,SDRAM SRAM DRAM( Here are the blue ones ) Can be collectively referred to RAM,random access memory( Random access memory ) Abbreviation , Here is For all of you ...

  3. Xcode Compile run error : CpResource /user/xxxx/ xxx Directory not empty

    I've had the same problem before , Always remember to eat or not , Step on the back of the pit will step in ... Just make an impression with the second mark Error characteristics RT Confirm that the type error is library or frameWork Of search routing problem First, find the way to compile errors ...

  4. Linux install Memcached service

    Environmental Science : CentOS 6.4 libevent-1.4.14b-stable memcached-1.4.21 See if it is installed libevent[root@localhost ~]# rpm -qa |g ...

  5. Sort-- Quick sort

    Quick sort 1 public class QuickSort{ 2 3 public static int Partition(int[] a,int low,int high){ 4 int pivo ...

  6. java: Java in this and super To sum up the usage of

    this this It's an object of its own , Represents the object itself , It can be understood as : A pointer to the object itself . this The usage of is in java In general, it can be divided into 3 Kind of : 1. A common direct quote I don't need to talk about this ,this It is equivalent to pointing to the current object ...

  7. WPF tab

    1. quote xmlns:xcad="" 2.xaml Code <xcad:DockingMa ...

  8. scala An overview of the ecosystem

    I believe many friends are right Scala I've heard about this new favorite programming language that combines object-oriented programming paradigm and functional programming paradigm ?! So once your project is selected Scala Technology stack , What other tools , Class libraries are optional ? Various types of frameworks or classes ...

  9. kali linux 2.0 After configuring the update source apt-get update Report errors

    This is me /etc/apt/sources.list Update source for : deb kali-rolling main contrib non-free deb ...

  10. docker The road of learning and Practice [ First stop ] Environmental installation

    Install virtual machine (VMware Workstation) I won't say much about this step , After downloading the software, click next all the way , Until installation is complete . install Ubuntu 16.4 server download ubuntu 16.4, And installed in a virtual machine ...