Correct variable names consist only of English letters, digits and underscores and they can't start with a digit.

Check if the given string is a correct variable name.

Example

    • For name = "var_1__Int", the output should be
      variableName(name) = true;
    • For name = "qq-q", the output should be
      variableName(name) = false;
    • For name = "2w2", the output should be
      variableName(name) = false.

我的解答:

def variableName(name):
dict = {'word':'qwertyuiopasdfghjklzxcvbnm', 'digit':'', 'underline':'_'}
if name[0].lower() in dict['word'] or name[0] in dict['underline']:
for i in name:
if i.lower() in dict['word'] or i in dict['underline'] or i in dict['digit']:
pass
else:
return False
return True
else:
return False
def variableName(name):
return name.isidentifier()

膜拜大佬

Code Signal_练习题_variableName的更多相关文章

  1. Code Signal_练习题_digitDegree

    Let's define digit degree of some positive integer as the number of times we need to replace this nu ...

  2. Code Signal_练习题_Knapsack Light

    You found two items in a treasure chest! The first item weighs weight1 and is worth value1, and the ...

  3. Code Signal_练习题_growingPlant

    Each day a plant is growing by upSpeed meters. Each night that plant's height decreases by downSpeed ...

  4. Code Signal_练习题_arrayMaxConsecutiveSum

    Given array of integers, find the maximal possible sum of some of its k consecutive elements. Exampl ...

  5. Code Signal_练习题_differentSymbolsNaive

    Given a string, find the number of different characters in it. Example For s = "cabca", th ...

  6. Code Signal_练习题_firstDigit

    Find the leftmost digit that occurs in a given string. Example For inputString = "var_1__Int&qu ...

  7. Code Signal_练习题_extractEachKth

    Given array of integers, remove each kth element from it. Example For inputArray = [1, 2, 3, 4, 5, 6 ...

  8. Code Signal_练习题_stringsRearrangement

    Given an array of equal-length strings, check if it is possible to rearrange the strings in such a w ...

  9. Code Signal_练习题_absoluteValuesSumMinimization

    Given a sorted array of integers a, find an integer x from a such that the value of abs(a[0] - x) + ...

随机推荐

  1. 【xsy2193】Wallace 最大权闭合子图

    题目大意:给你一棵$n$个节点的树$a$,每个点有一个点权$val_i$,同时给你另一棵$n$个节点的树$b$. 现在你需要在树$a$上找一个联通块,满足这些点在树$b$上也是连通的,同时树$a$的这 ...

  2. django-suit报错解决-----from suit.apps import DjangoSuitConfig

    (py27) [root@test SimpletourDevops]# python manage.py makemigrationsTraceback (most recent call last ...

  3. windows2016 安装mysql5.7

    下载msi安装包,一路下一步. 安装好后,做下简单配置. 默认的my.ini和datadir在C:\ProgramData\MySQL Server 5.7下 更改默认my.ini的方法为修改注册表 ...

  4. java项目日志写到logstash-TCP/UDP

    好处:项目日志写到logstash,然后发送到ElasticSearch,可以方便查看搜索日志,还可以做报表分析. logstash是一个数据采集工具,有多种渠道,比如文件,tcp,udp等,如果是采 ...

  5. 在Android中调用KSOAP2库访问webservice服务出现的服务端返回AnyType{}

    最近在做毕业设计的时候,涉及到了安卓端访问web service服务端数据库,并返回一个值,当我把web service测试通过后,想写一个简单的安卓测试程序,来实现服务端数据库访问,通过web se ...

  6. JAVA多态计算面积main函数调用方法

    public static void main(String[] args) { Shape shape; Scanner input = new Scanner(System.in); System ...

  7. tabs高度自适应方法

    1.去掉easyui-tabs类属性,改为id=tabs 2.用js控制高度

  8. vue数组检测更新问题

    由于 JavaScript 的限制, Vue 不能检测以下变动的数组: 当你利用索引直接设置一个项时,例如: vm.items[indexOfItem] = newValue 当你修改数组的长度时,例 ...

  9. PHP MYSQL登陆和模糊查询

    PHP MYSQL登陆和模糊查询   PHP版本 5.5.12    MYSQL版本 5.6.17  Apache 2.4.9 用的wampserver 一.PHPMYSQL实现登陆:  一共含有两个 ...

  10. SQL-结构化查询语言(2)

    使用explain查询select查询语句的执行计划 mysql> explain select * from student where Sname='金克斯'\G ************* ...