Trying to shorten the following:
Code:
# for each edge, attempt to ping it up to 5 times
for edge in edges:
for count in range(5):
ping = os.system('ping -c 1 ' + edge['defaultNat'])
if ping == 0:
break
elif count > 3:
failed_edges.append(edge)
to a one liner (ala list comprehension). I was thinking something along the lines of:
Code:
[os.system('ping -c 1 ' + edge['defaultNat']) for edge in edges for _ in range(5)]
but I'm stuck on referencing the output of the system call and short-circuiting if it's successful. (any()?)
Any suggestions?