Code Signal_练习题_firstDigit
Posted yd2018
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Code Signal_练习题_firstDigit相关的知识,希望对你有一定的参考价值。
Find the leftmost digit that occurs in a given string.
Example
- For
inputString = "var_1__Int"
, the output should befirstDigit(inputString) = ‘1‘
; - For
inputString = "q2q-q"
, the output should befirstDigit(inputString) = ‘2‘
; - For
inputString = "0ss"
, the output should befirstDigit(inputString) = ‘0‘
.
我的解答:
def firstDigit(inputString): return [i for i in inputString if i.isdigit()][0]
def firstDigit(inputString): for i in inputString: if i.isdigit(): return i
以上是关于Code Signal_练习题_firstDigit的主要内容,如果未能解决你的问题,请参考以下文章
Code Signal_练习题_stringsRearrangement