Skip to content

Instantly share code, notes, and snippets.

@pwnall1337
Last active April 24, 2017 01:43
Show Gist options
  • Save pwnall1337/6b9d13667f1be5ad193f3b4a656d6c9f to your computer and use it in GitHub Desktop.
Save pwnall1337/6b9d13667f1be5ad193f3b4a656d6c9f to your computer and use it in GitHub Desktop.
#load files line by line into memory and use recursive list comprehension. written in 30 min.
pwnall@pwnall-desktop:~$ cat fbtest2.py
#!/usr/bin/env python
def open_csv(fd):
data=[]
with open(fd, 'r') as f:
for line in f:
row=line.split('\n')
s=[s.lstrip() for r in row for s in r.split(',') if len(r) >2 and not s.startswith('NAME')]
data.append(s)
return data
def speed(stride,leg):
g=9.8
speed=((( stride / leg) -1) * (leg*g)**.5)
return speed
def compare(data1, data2):
dinos=[]
for s in data1:
sname=s[0]
leg=s[1]
for d in data2:
dname=d[0]
stride=d[1]
stance=d[2]
if sname==dname and stance=='bipedal':
dino_speed=speed(float(stride), float(leg))
dinos.append((sname, dino_speed))
return dinos
data1=open_csv('data1.csv')
data2=open_csv('data2.csv')
dinos_sorted=sorted(compare(data1, data2),key=lambda x:x[1], reverse=True)
for dino in dinos_sorted:
print dino[0]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment