List

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

DIRAC.Core.Utilities.List.appendUnique(aList: list, anObject: Any)

Append to list if object does not exist.

Parameters:
  • aList – list of elements

  • anObject – object you want to append

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

It returns a list of lists.

Parameters:
  • aList – list of elements

  • chunkSize – 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: str, sepChar: str = ',')

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

Parameters:
  • inputString – list serialised to string

  • sepChar – separator

Returns:

list of strings or None if sepChar has a wrong type

DIRAC.Core.Utilities.List.getChunk(aList: list, chunkSize: int)

Generator yielding chunk from a list of a size chunkSize.

Parameters:
  • aList – list to be splitted

  • chunkSize – lenght of one chunk

Raise:

StopIteration

Usage:

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

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 to look into

Returns:

the index or sys.maxint

DIRAC.Core.Utilities.List.intListToString(aList: list) str

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

Parameters:

aList – 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: list) list

Return a randomly sorted list.

Parameters:

aList – list to permute

DIRAC.Core.Utilities.List.stringListToString(aList: list) str

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

Parameters:

aList – list to be serialized to string for making queries

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

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