List

Collection of DIRAC useful list related modules. By default on Error they return None.

DIRAC.Core.Utilities.List.appendUnique(aList, anObject)

Append to list if object does not exist.

Parameters
  • aList (list) – list of elements

  • anObject – object you want to append

DIRAC.Core.Utilities.List.breakListIntoChunks(aList, chunkSize)
This function takes a list as input and breaks it into list of size ‘chunkSize’.

It returns a list of lists.

Parameters
  • aList (list) – list of elements

  • chunkSize (int) – len of a single chunk

Returns

list of lists of length of chunkSize

Raise

RuntimeError if numberOfFilesInChunk is less than 1

DIRAC.Core.Utilities.List.fromChar(inputString, sepChar=',')

Generates a list splitting a string by the required character(s) resulting string items are stripped and empty items are removed.

Parameters
  • inputString (string) – list serialised to string

  • sepChar (string) – separator

Returns

list of strings or None if sepChar has a wrong type

DIRAC.Core.Utilities.List.getChunk(aList, chunkSize)

Generator yielding chunk from a list of a size chunkSize.

Parameters
  • aList (list) – list to be splitted

  • chunkSize (int) – lenght of one chunk

Raise

StopIteration

Usage:

>>> for chunk in getChunk( aList, chunkSize=10):
      process( chunk )
DIRAC.Core.Utilities.List.getIndexInList(anItem, aList)

Return the index of the element x in the list l or sys.maxint if it does not exist

Parameters
  • anItem – element to look for

  • aList (list) – list to look into

Returns

the index or sys.maxint

DIRAC.Core.Utilities.List.intListToString(aList)

This function is used for making MySQL queries with a list of int elements.

Parameters

aList (list) – list to be serialized to string for making queries

DIRAC.Core.Utilities.List.pop(aList, popElement)

Pop the first element equal to popElement from the list.

Parameters
  • aList (list) – list

  • popElement – element to pop

DIRAC.Core.Utilities.List.randomize(aList)

Return a randomly sorted list.

Parameters

aList (list) – list to permute

DIRAC.Core.Utilities.List.stringListToString(aList)

This function is used for making MySQL queries with a list of string elements.

Parameters

aList (list) – list to be serialized to string for making queries

DIRAC.Core.Utilities.List.uniqueElements(aList)

Utility to retrieve list of unique elements in a list (order is kept).

Parameters

aList (list) – list of elements

Returns

list of unique elements