Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # 4.py
- """
- ferramenta #1
- auxiliar para a geração de modelos
- """
- def getListOfAlternatingTrueFalse(
- piHowManyValues:int,
- piAlternateEveryN:int=1,
- pbStartValue:bool=True
- ):
- retList = list()
- retList = []
- bCurrentValue = pbStartValue
- while(len(retList)<piHowManyValues):
- retList.append(bCurrentValue)
- bAlternateTime:bool = \
- len(retList)%piAlternateEveryN == 0
- if(bAlternateTime):
- bCurrentValue = not bCurrentValue
- # while
- return retList
- # def getListOfAlternatingTrueFalse
- """
- l1 = getListOfAlternatingTrueFalse(
- 33,
- piAlternateEveryN=4,
- pbStartValue=True
- )
- print (l1)
- """
- """
- 1 prop (1 var) => basta 1 lista q alterne de 1-1
- 2 props (2 vars) => 2 listas (1-1 , 2-2)
- 3 props (3 vars) => 3 listas (1-1 , 2-2, 4-4)
- n props (n vars) => n listas (2**0=1, 2**1=2, ... 2**n-1)
- ferramenta auxiliar para compilar todas as listas
- de combinações possíveis
- """
- def getAllPossibleAlternatingListsForNProps(
- pN:int=2,
- pbStartValue:bool=True
- ):
- retListOfLists = list()
- iHowManyCombosThereAreForNProps = 2**pN
- iCurrentList = 0
- while(len(retListOfLists)<pN):
- listOfAlternatingValues = \
- getListOfAlternatingTrueFalse(
- piHowManyValues=iHowManyCombosThereAreForNProps,
- piAlternateEveryN=2**iCurrentList,
- pbStartValue=pbStartValue
- )
- retListOfLists.append(listOfAlternatingValues)
- iCurrentList+=1
- # while
- return retListOfLists
- # def getAllPossibleAlternatingListsForNProps
- """
- l2 = getAllPossibleAlternatingListsForNProps(3)
- print (l2)
- """
- def getAllModelsForNProps(
- pN:int=2,
- pbStartValue:bool=True
- ):
- retListOfAllPossibleModels = list()
- listAlts =\
- getAllPossibleAlternatingListsForNProps(
- pN=pN,
- pbStartValue=pbStartValue
- )
- for idxValue in range(2**pN):
- currentModel = list()
- for idxListAlt in range(len(listAlts)):
- currentList = listAlts[idxListAlt]
- bCurrentValue:bool = currentList[idxValue]
- currentModel.append(bCurrentValue)
- # for
- # a new model is ready
- currentModel.reverse() # in-place
- retListOfAllPossibleModels.append(
- currentModel
- )
- # for
- return retListOfAllPossibleModels
- # def getAllModelsForNProps
- """
- models = getAllModelsForNProps(3)
- print(models)
- """
- def getAllDictModelsForNamedProps(
- pListNamedProps = ["a", "b", "c"]
- ):
- retListOfDictModels = list()
- iHowManyProps = len(pListNamedProps)
- allModels = getAllModelsForNProps(pN=iHowManyProps)
- for idxModel in range(len(allModels)):
- currentModel = allModels[idxModel]
- newDictModel = dict()
- for idxProp in range(len(pListNamedProps)):
- strCurrentProp = pListNamedProps[idxProp]
- bCurrentValue:bool = currentModel[idxProp]
- newDictModel[strCurrentProp] = bCurrentValue
- # for
- # new model (as dict)
- retListOfDictModels.append(newDictModel)
- # for
- return retListOfDictModels
- # def getAllDictModelsForNamedProps
- allModelsAsDicts = getAllDictModelsForNamedProps(
- ["troveja", "chove", "durmo"]
- )
- print(allModelsAsDicts)
Advertisement
Add Comment
Please, Sign In to add comment