Check if a string contains a number

后端 未结 16 1364
無奈伤痛
無奈伤痛 2020-11-22 11:14

Most of the questions I\'ve found are biased on the fact they\'re looking for letters in their numbers, whereas I\'m looking for numbers in what I\'d like to be a numberless

16条回答
  •  粉色の甜心
    2020-11-22 11:47

    This probably isn't the best approach in Python, but as a Haskeller this lambda/map approach made perfect sense to me and is very short:

    anydigit = lambda x: any(map(str.isdigit, x))

    Doesn't need to be named of course. Named it could be used like anydigit("abc123"), which feels like what I was looking for!

提交回复
热议问题