Skip to content

Instantly share code, notes, and snippets.

@codemartial
Created March 13, 2014 04:31
Show Gist options
  • Save codemartial/9521921 to your computer and use it in GitHub Desktop.
Save codemartial/9521921 to your computer and use it in GitHub Desktop.
A filter to normalise focal lengths to the nearest standard focal length
#!/usr/bin/python
import sys
limits = [16.0, 24.0, 28.0, 35.0, 50.0, 70.0, 85.0, 105.0, 135.0, 150.0, 180.0, 200.0, 210.0, 300.0, 450.0, 600.0]
if __name__ == "__main__":
for line in sys.stdin:
fl = float(line)
diffs = dict([(abs(x - fl), x) for x in limits])
print diffs[min(diffs)]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment