Skip to content

Instantly share code, notes, and snippets.

@gkmngrgn
Created November 10, 2012 23:51
Show Gist options
  • Save gkmngrgn/4053025 to your computer and use it in GitHub Desktop.
Save gkmngrgn/4053025 to your computer and use it in GitHub Desktop.
try:
size = map(lambda x: int(x), size)
except ValueError:
size = map(lambda x: int(x), self.default_size)
@huseyinyilmaz
Copy link

    try:
        size = map(int, size)
    except ValueError:
        size = map(int, self.default_size)

Is there any way to do this without using Exceptions

 size = map(int,size if all(imap(methodcaller('isdigit'), size)) else self.default_size)

No Exception, but if we have a list that have only integer strings, we will iterate over the list twice.

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