Skip to content

Instantly share code, notes, and snippets.

@linduxed
Created February 16, 2016 23:27
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save linduxed/9fcd27c436d58dc84bc3 to your computer and use it in GitHub Desktop.
(0..3).map { |n| "/home/linduxed/foo/#{n}/bar" }.find { |f| File.exist?(f) }
@georgebrock
Copy link

import os

possible_paths = ["/home/linduxed/foo/%d/bar" % n for n in range(0, 4)]

try:
    next(path for path in possible_paths if os.path.exists(path))
except StopIteration:
    # handle the "none of these files exists" case

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment