Feb-13-2017, 08:49 PM
Ok, so let's use that as an example. Here's how I'd write it (without spending a ton of time thinking about it) ... (and honestly, my first thought was just
is_number = lambda x: x.isdigit()
lol)>>> def is_number(s): ... try: ... ignore = float(s) ... return True ... except ValueError: ... pass ... return False ... >>> is_number(5) True >>> is_number("7") True >>> is_number("-7.432") True >>> is_number("your mom") FalseYou guys must be more impressive than me. I've always been on the receiving end of interviews, never the giving end :p