i have to search for certain patterns in a file that i have to open. If all the variables find the patterns, my code works fine, but if any pattern is not found, i receive the following error:
str2 = len(max(re.findall(r'(?:TTTTTTCT)+', data))) // 8
ValueError: max() arg is an empty sequence
what can i do to assign a default value to not receive this error in case one of the variables receive an empty sequence?
Sorry if i can't explain properly, english is not my native language and also i'm a beginner
these are my variables:
with open(sys.argv[2], "r") as myfile:
data = myfile.read()
str1 = len(max(re.findall(r'(?:AGATC)+', data))) // 5
str2 = len(max(re.findall(r'(?:TTTTTTCT)+', data))) // 8
str3 = len(max(re.findall(r'(?:AATG)+', data))) // 4
str4 = len(max(re.findall(r'(?:TCTAG)+', data))) // 5
str5 = len(max(re.findall(r'(?:GATA)+', data))) // 4
str6 = len(max(re.findall(r'(?:TATC)+', data))) // 4
str7 = len(max(re.findall(r'(?:GAAA)+', data))) // 4
str8 = len(max(re.findall(r'(?:TCTG)+', data))) // 4
maxcall to be doing. Currently it will select the lexicographically maximal string matched by your regex but it's not clear that's actually what you want. If you want the longest string, you probably want to be callinglenearlier, and you might be able to inject a zero more easily than you can with your current code.