I’m getting the type error at the return statement ‘Value after * must be an iterable, not bool’. I have no idea where it comes from, the code seems right, all the * come before an iterator, as can be readily seen by analysing the type declarations.
[SOLVED]: the problem had to do with the base cases ([False for _ in range(totalLength)]) is a list, not an iterator of lists.
def getConfigs(runs:list[int], totalLength :int)->Iterable[list[bool]]: ”’Given a list of runs and a length it returns an iterator of all available configurations of True and False within the length, such that every run of True is separated by at least a white piece.”’ if runs == []:return ([False for _ in range(totalLength)]) #Trivial case when there are no runs if sum(runs)+len(runs)-1>totalLength: return () #Case in which it’s impossible to find a proper configuration return ([*(False for _ in range(runStartingPoint)) , *(True for _ in range(runs[0])) , False , *nextConfig] for runStartingPoint in range(totalLength-runs[0]+1) for nextConfig in getConfigs(runs[1:],totalLength-runStartingPoint-runs[0]-1))
submitted by /u/TESanfang
[link] [comments]
r/learnpython I’m getting the type error at the return statement ‘Value after * must be an iterable, not bool’. I have no idea where it comes from, the code seems right, all the * come before an iterator, as can be readily seen by analysing the type declarations. [SOLVED]: the problem had to do with the base cases ([False for _ in range(totalLength)]) is a list, not an iterator of lists. def getConfigs(runs:list[int], totalLength :int)->Iterable[list[bool]]: ”’Given a list of runs and a length it returns an iterator of all available configurations of True and False within the length, such that every run of True is separated by at least a white piece.”’ if runs == []:return ([False for _ in range(totalLength)]) #Trivial case when there are no runs if sum(runs)+len(runs)-1>totalLength: return () #Case in which it’s impossible to find a proper configuration return ([*(False for _ in range(runStartingPoint)) , *(True for _ in range(runs[0])) , False , *nextConfig] for runStartingPoint in range(totalLength-runs[0]+1) for nextConfig in getConfigs(runs[1:],totalLength-runStartingPoint-runs[0]-1)) submitted by /u/TESanfang [link] [comments]
I’m getting the type error at the return statement ‘Value after * must be an iterable, not bool’. I have no idea where it comes from, the code seems right, all the * come before an iterator, as can be readily seen by analysing the type declarations.
[SOLVED]: the problem had to do with the base cases ([False for _ in range(totalLength)]) is a list, not an iterator of lists.
def getConfigs(runs:list[int], totalLength :int)->Iterable[list[bool]]: ”’Given a list of runs and a length it returns an iterator of all available configurations of True and False within the length, such that every run of True is separated by at least a white piece.”’ if runs == []:return ([False for _ in range(totalLength)]) #Trivial case when there are no runs if sum(runs)+len(runs)-1>totalLength: return () #Case in which it’s impossible to find a proper configuration return ([*(False for _ in range(runStartingPoint)) , *(True for _ in range(runs[0])) , False , *nextConfig] for runStartingPoint in range(totalLength-runs[0]+1) for nextConfig in getConfigs(runs[1:],totalLength-runStartingPoint-runs[0]-1))
submitted by /u/TESanfang
[link] [comments]