Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Analogues of Perl's modules List::Util, List::MoreUtils functionality in Python [closed]

Tags:

python

perl

There's a very useful thing in Perl for functional style lists manipulation List::Util, List::MoreUtils. Is there an analogue for Python? I particularly interested in uniq, reduce, any, all and none.

Mentioned modules offer functions:

  • first max maxstr min minstr reduce shuffle sum
  • any all none notall true false firstidx first_index lastidx last_index insert_after insert_after_string apply indexes after after_incl before before_incl firstval first_value lastval last_value each_array each_arrayref pairwise natatime mesh zip uniq distinct minmax part
like image 518
Sergey Romanovsky Avatar asked Sep 08 '26 06:09

Sergey Romanovsky


1 Answers

Most of the functions you mention are already built-in, including reduce(), any() or all().

I am not familiar with Perl, but from what I understand from the links you provide the equivalent of uniq in Python could be set() (and if you want to keep the original order, list(OrderedDict.fromkeys(mylist)) can be a solution).

like image 126
A. Rodas Avatar answered Sep 09 '26 19:09

A. Rodas