def order_by( groups: typing.List, order_type: typing.Union[str, list, tuple], default_type: str = None ) -> typing.List: """ Orders a list of groups by the specified order type, or the default type if the order type is 'DEFAULT' or unrecognized :param groups: A list of aisle or passenger index groups to sort by the specified order :param order_type: The enumerated order type, such as 'RANDOM', 'FORWARD', or 'BACKWARD' :param default_type: A default order type to use if the order_type is 'DEFAULT' or the order type is not recognized :return: The list of groups that has been sorted """ order_type = order_type.upper() if isinstance(order_type, (list, tuple)): ordering = [order_type.index(x + 1) for x in range(len(groups))] return [x for (y, x) in sorted(zip(ordering, groups))] if order_type == 'BACKWARD': groups.reverse() return groups if order_type == 'FORWARD': return groups if order_type == 'RANDOM': random.shuffle(groups) return groups if default_type: return order_by(groups, default_type) raise ValueError( 'Invalid configuration setting populate.group_order of "{}"'.format( order_type ) )
def pick_element(a_list: typing.List, remove: bool=False): element = random.choice(a_list) if remove: a_list.remove(element) return element
def lst_append(lst: typing.List, *args): for arg in args: lst.append(arg)
def __init__(self, name: str): self._name = name self._faces: List(MeshFace) = []
def merge(list: typing.List, elm): return list.extend(elm)