аватар question@mail.ru · 01.01.1970 03:00

The number of repeated elements in the list

There is an array in which a bunch of repeated elements. I need to derive the contents of a particular element of this array and how many of the same elements in it (derive the figure).
An example of an array:

  Array = [ "" Bob "" ,  "alex" ", , ]     

(like 2 bean, etc.)

аватар answer@mail.ru · 01.01.1970 03:00

The easiest way to calculate the number of entries of all elements is to use the built -in class from the module:

  in [ 4 ]:  from  collections  import  counterin [ 5 ]: array = [ "" bob "" ,  "Alex" ", , ] in [ 6 ]: C = coonter (Array) inininininin [ 7 ]: cout [ 7 ]: counter ({ '">' "> '" "" bob' :  2 ,  'Alex' :  1 ,  'jhn' :  1 }) in [ 8 ]: C [ 'bob' ] out [ 8 ]:  2  in [ 9 ]: C [ 'unknown' ] out [ 9 ]:  0                                        

Latest

Similar