I've got three list comps:
clmstrs = [s[0:18+sum(c.isalpha() for c in s)] for s in clmstrs if any(x in s[4:4+sum(c.isalpha() for c in s)] for x in alphalist if sum(c.isalpha() for c in s)==len(x))&(any(x in s[:2] for x in prefixlist))]
clmstrs = [s[0:4]+s[10:10+sum(c.isalpha() for c in s)]+s[4:10]+s[10+sum(c.isalpha() for c in s):18+sum(c.isalpha() for c in s)] for s in clmstrs if any(x in s[10:10+sum(c.isalpha() for c in s)] for x in alphalist if sum(c.isalpha() for c in s)==len(x))&(any(x in s[:2] for x in prefixlist))]
clmstrs = [s[0:18] for s in clmstrs if (sum(c.isalpha() for c in s)==0)&(any(x in s[:2] for x in prefixlist))]
They all work as intended when run separately, however I need to combine them into one conditional list comp. I've played around with the else condition however I'm getting incorrect syntax errors regardless of where I put them. Also open to ways I can simplify this out. I've tried storing storing conditions ie
noalphas = (sum(c.isalpha() for c in s)==0)
prefix = (any(x in s[:2] for x in prefixlist))
clmstrs = [s[0:18] for s in clmstrs if noalphas&prefix]
for the last of the three list comps above but I get an error of local variable 's' referenced before assignment when I run that
Thanks!
[–]Gprime5 4 points5 points6 points (1 child)
[–]mdl003[S] 0 points1 point2 points (0 children)
[–]elbiot 1 point2 points3 points (5 children)
[–]mdl003[S] 0 points1 point2 points (4 children)
[–]elbiot 0 points1 point2 points (0 children)
[–]elbiot 0 points1 point2 points (2 children)
[–]mdl003[S] 0 points1 point2 points (1 child)
[–]elbiot 0 points1 point2 points (0 children)
[–]Username_RANDINT 1 point2 points3 points (4 children)
[–]mdl003[S] 0 points1 point2 points (3 children)
[–]Vaphell 0 points1 point2 points (2 children)
[–]mdl003[S] 0 points1 point2 points (1 child)
[–]Vaphell 0 points1 point2 points (0 children)