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. 异常处理,约束,MD5加密日志处理

    程序运行过程中产生的错误, 不正常 def chufa(a, b): try: # 尝试执行xxx代码 ret = a/b # 如果这里出现了错误. 异常. 系统内部会产生一个异常对象. 系统会把这个 ...

  2. redis常用命令(一)

    一.redis常见的数据操作命令 http://redisdoc.com/ 二.键(key) keys *: 查询所有的key. exists key:判断某个key是否存在. move key db ...

  3. (转)Python的web服务器

    1.浏览器请求动态页面过程 2.WSGI Python Web Server Gateway Interface (或简称 WSGI,读作“wizgy”). WSGI允许开发者将选择web框架和web ...

  4. 我的Git教程 之 解决 git clone后无代码

    解决 git clone 后无代码 前言:这个教程只适用于像我一样大致理解Git的原理,但是不太记得住Git命令的同学使用.所以具体原理只会提一下,具体可以参见Pro Git. 在另一篇 简明的教程  ...

  5. Python+selenium+webdriver 安装与环境配置

    1.python安装:访问python.org/download,下载最新版本,安装过程与其他windows软件类似.记得下载后设置path环境变量,然后Windows命令行就可以调用: 2.Sele ...

  6. Java 调用系统命令

    ProcessBuilder import java.io.File; import java.io.IOException; import java.io.InputStream; import j ...

  7. Git学习系列之CentOS上安装Git详细步骤(图文详解)

    前言 最早Git是在Linux上开发的,很长一段时间内,Git也只能在Linux和Unix系统上跑.不过,慢慢地有人把它移植到了Windows上.现在,Git可以在Linux.Unix.Mac和Win ...

  8. Apache版本的Hadoop HA集群启动详细步骤【包括Zookeeper、HDFS HA、YARN HA、HBase HA】(图文详解)

    不多说,直接上干货! 1.先每台机器的zookeeper启动(bigdata-pro01.kfk.com.bigdata-pro02.kfk.com.bigdata-pro03.kfk.com) 2. ...

  9. docker(三)docker镜像和镜像发布方法

    一.从公网docker hub 拉取image ~ # 搜索docker search centos~ » docker pull centos admin@steven- Using default ...

  10. 【胡思乱想】命令模式中,命令对象如何解耦Invoker和Receiver

    首先,我们得清楚为何要解耦? 耦合的坏处就是,牵一发而动全身,比如,当我更改了类A或其子类的时候,类B也要进行修改.这里,解除耦合,就意味着,即使你Receiver怎么改,添加了多少,删除了多少.我I ...