List Object

class List(data=None)

Object which extends python list object to include LINQ style queries.

all(expression)

Checks to see if all items in a list meet a conditional criteria. E.g. List.all(“x > 0”).

Parameters:expression (str or LambdaType) – The expression to apply to the List object, which must be a conditional statement. Can either take a string (“x > 0”) or a lambda expression (lambda x : x > 0).
Returns:a bool that is true if all elements satisfy the applied expression.
any(expression)

Checks to see if any items in a list meet a conditional criteria. E.g. List.any(“x > 0”).

Parameters:expression (str or LambdaType) – The expression to apply to the List object, which must be a conditional statement. Can either take a string (“x > 0”) or a lambda expression (lambda x : x > 0).
Returns:a bool that is true if any elements satisfy the applied expression.
append(val)

S.append(value) – append value to the end of the sequence

clear() → None -- remove all items from S
concat(other)

Adds all the elements of another List object onto the calling List object. E.g. List1.concat(List2)

Parameters:other (List) – Another List instance to concatinate with the calling List.
Returns:a new List object that is the concatination of self and other.
count(expression=None)

Counts the number of items in a list that meet a conditional criteria. E.g. List.count(“x > 0”).

Parameters:expression (str or LambdaType or None) – The expression to apply to the List object, which must be a conditional statement. Can either take a string (“x > 0”) or a lambda expression (lambda x : x > 0).
Returns:an integer representing the number of elements that satisfy the applied expression.
distinct(expression=None)

Checks to see if any items in a list meet a conditional criteria, and also removes duplicates. E.g. List.distinct(“x > 0”).

Parameters:expression (str or LambdaType or None) – The expression to apply to the List object, which must be a conditional statement. If no expression is supplied, then function acts on the whole list. Can either take a string (“x > 0”) or a lambda expression (lambda x : x > 0).
Returns:a new List object that results from the applied expression.
duplicate(expression=None)

Checks to see if any items in a list meet a conditional criteria, but only if they are duplicate items. E.g. List.duplicate(“x > 0”).

Parameters:expression (str or LambdaType or None) – The expression to apply to the List object, which must be a conditional statement. If no expression is supplied, then function acts on the whole list. Can either take a string (“x > 0”) or a lambda expression (lambda x : x > 0).
Returns:a new List object that results from the applied expression.
element(number)

Returns the item at a specified index. E.g. List.element(0)

Parameters:number (int) – The index to get the item from.
Returns:an item from the list or None if index is out of range.
except_set(other)

Removes all instances from a list that exist in another list exept for duplicates. E.g. List1.except_set(List2)

Parameters:other (List) – Another List instance to compare entries with the calling List.
Returns:a new List object that contains all items in self, except any item that exist in other.
first(expression=None)

Finds the first item in a list that meets a conditional criteria. E.g. List.first(“x > 0”).

Parameters:expression (str or LambdaType or None) – The expression to apply to the List object, which must be a conditional statement. If no expression is supplied, then function acts on the whole list. Can either take a string (“x > 0”) or a lambda expression (lambda x : x > 0).
Returns:an item from the list or None if nothing is found.
groupby(expression)

Uses a parameter of that data to group all entries according to key values. E.g. List.groupby(“x[‘key’]”).

Parameters:expression (str or LambdaType) – The expression to apply to the List object. Can either take a string (“x[0]”) or a lambda expression (lambda x : x[0]).
Returns:a new List object that results from the applied expression.
insert(ii, val)

S.insert(index, value) – insert value before index

intersect(other)

Returns all entries that are common between two lists without duplicates. E.g. List1.intersect(List2)

Parameters:other (List) – Another List instance to compare entries with the calling List.
Returns:a new List object that contains all items that exist in both self and other.
last(expression=None)

Finds the last item in a list that meets a conditional criteria. E.g. List.last(“x > 0”).

Parameters:expression (str or LambdaType or None) – The expression to apply to the List object, which must be a conditional statement. If no expression is supplied, then function acts on the whole list. Can either take a string (“x > 0”) or a lambda expression (lambda x : x > 0).
Returns:an item from the list or None if nothing is found.
max(expression=None)

Finds the maximum value item in a list. Optionally, the item can be applied to a conditional criteria. E.g. List.max(“x > 0”) or List.max(“x**2”).

Parameters:expression (str or LambdaType or None) – The expression to apply to the List object. Can also be an operation or function to apply to elements. If no expression is supplied, then function acts on the whole list. Can either take a string (“x > 0”) or a lambda expression (lambda x : x > 0).
Returns:an item from the list or None if nothing is found.
min(expression=None)

Finds the minimum value item in a list. Optionally, the item can be applied to a conditional criteria. E.g. List.min(“x > 0”) or List.min(“x**2”).

Parameters:expression (str or LambdaType or None) – The expression to apply to the List object. Can also be an operation or function to apply to elements. If no expression is supplied, then function acts on the whole list. Can either take a string (“x > 0”) or a lambda expression (lambda x : x > 0).
Returns:an item from the list or None if nothing is found.
oftype(elementType)

Checks to see if any items in a list are of a certain type. E.g. List.oftype(int)

Parameters:elementType (str or type) – The expression to apply to the List object. Can either take a string “int”,”dict”,”List”, etc. or a type.
Returns:a new List object that contains only items of the specified type.
orderby(expression=None, reverse=False)

Orders the items in a list by a certain value. Optionally, the item can be applied to a conditional criteria. E.g. List.orderby(“x > 0”) or List.orderby(“len(x)”).

Parameters:
  • expression (str or LambdaType or None) – The expression to apply to the List object, which must be a conditional statement. If no expression is supplied, then function acts on the whole list. Can either take a string (“x > 0”) or a lambda expression (lambda x : x > 0).
  • reverse (bool) – True if the list should be descending. False if the list should be ascending.
Returns:

a new List object that results from the applied expression.

pop([index]) → item -- remove and return item at index (default last).

Raise IndexError if list is empty or index is out of range.

remove(val)

S.remove(value) – remove first occurrence of value. Raise ValueError if the value is not present.

select(expression)

Applies an operator or function to each item in the list. E.g. List.select(“len(x)”).

Parameters:expression (str or LambdaType) – The expression to apply to the List object. Can either take a string (“x**2”) or a lambda expression (lambda x : x**2).
Returns:a new List object that results from the applied expression.
skipwhile(expression)

Returns all elements after the first item in the list that fails to meet a conditional criteria. E.g. List.skipwhile(“x > 0”).

Parameters:expression (str or LambdaType) – The expression to apply to the List object, which must be a conditional statement. Can either take a string (“x > 0”) or a lambda expression (lambda x : x > 0).
Returns:a new List object that results from the applied expression.
sum(expression=None)

Finds the sum of all values in a list. Optionally, the item can be applied to a conditional criteria. E.g. List.sum(“x > 0”) or List.sum(“x**2”)

Parameters:expression (str or LambdaType or None) – The expression to apply to the List object. Can also be an operation or function to apply to elements. If no expression is supplied, then function acts on the whole list. Can either take a string (“x > 0”) or a lambda expression (lambda x : x > 0).
Returns:an item from the list or None if nothing is found.
takewhile(expression)

Returns all elements before the first item in the list that fails to meet a conditional criteria. E.g. List.takewhile(“x > 0”).

Parameters:expression (str or LambdaType) – The expression to apply to the List object, which must be a conditional statement. Can either take a string (“x > 0”) or a lambda expression (lambda x : x > 0).
Returns:a new List object that results from the applied expression.
union(other)

Returns all entries for two Lists except for any duplicates. E.g. List1.union(List2)

Parameters:other (List) – Another List instance to compare entries with the calling List.
Returns:a new List object that contains all items in self and other, except any duplicates.
where(expression)

Checks to see if any items in a list meet a conditional criteria. E.g. List.where(“x > 0”).

Parameters:expression (str or LambdaType) – The expression to apply to the List object, which must be a conditional statement. If no expression is supplied, then function acts on the whole list. Can either take a string (“x > 0”) or a lambda expression (lambda x : x > 0).
Returns:a new List object that results from the applied expression.