Ok so I made a method in python that does exactly what I want it to but its really ugly and repetitive, all it needs to do is get the first 4 integers in a string of input and return them in the form ((int1, int2), (int3, int4)). There has got to be a better way of doing this (maybe even in one line) using list comprehension or something of that sort. Any ideas??
def getMove(playerInput) :
nextNum = 0
x1 = 0
y1 = 0
x2 = 0
y2 = 0
for c in playerInput:
try:
if nextNum==0 :
x1 = int(c)
nextNum += 1
elif nextNum==1 :
y1 = int(c)
nextNum += 1
elif nextNum==2 :
x2 = int(c)
nextNum += 1
elif nextNum==3 :
y2 = int(c)
nextNum += 1
else :
return ((x1,y1),(x2,y2))
except ValueError:
break
return ((x1,y1), (x2,y2))
Thanks in advance for your helpful comments.