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. mysql创建账号及管理权限

    mysql创建账号及管理权限 0.mysql版本8.0.15,服务器版本:RHEL 6.5 1.创建用户名密码 mysql> use mysql; mysql> create user ' ...

  2. Redis---skipList(跳跃列表)

    1. 概述 跳跃表是一种有序的数据结构, 他通过在每个节点中维持多个指向其他节点的指针, 从而达到快速访问节点的目的. 大部分情况下, 跳跃表的效率可以和平衡树相媲美. Redis中只在两处用到了跳跃 ...

  3. ES6 模块定义 export 与 import

    一般导出 export math.js export function* getFibo() { let a = 1; let b = 1; yield a; yield b; while (true ...

  4. (转)Python3 模块3之 Urllib之 urllib.parse、urllib.robotparser

    原文:https://blog.csdn.net/qq_36148847/article/details/79153738 https://blog.csdn.net/zly412934578/art ...

  5. Quartz.NET在ASP.NET 中使用

    Quartz.NET 项目地址 http://quartznet.sourceforge.net/ common logging是一个通用日志接口,log4net是一个具体实现 ,也可以使用NLog, ...

  6. javascript保留字趣史

    转载自[https://mathiasbynens.be/notes/reserved-keywords](https://mathiasbynens.be/notes/reserved-keywor ...

  7. puppeteer(headless chrome)实现网站登录

    puppeteer简介 puppeteer是Chrome团队开发的一个node库,可以通过api来控制浏览器的行为,比如点击,跳转,刷新,在控制台执行js脚本等等.有了这个神器,写个爬虫,自动签到,网 ...

  8. 自制“低奢内”CSS3注册表单,包含JS验证哦。请别嫌弃,好吗?。

    要求 必备知识 基本了解CSS语法,初步了解CSS3语法知识.和JS/JQuery基本语法. 开发环境 Adobe Dreamweaver CS6 演示地址 演示地址 预览截图(抬抬你的鼠标就可以看到 ...

  9. hbase和zookeeper的安装和部署

    1.概要 1.1HBase的使用场景  大数据量 (100s TB级数据) 且有快速随机访问的需求.  例如淘宝的交易历史记录.数据量巨大无容置疑,面向普通用户的请求必然要即时响应.  容量的优 ...

  10. php交叉合并数组

    如数组 array1 = array('a', 'b', 'c');     array2 = array('1', '2', '3'); 希望能实现结果 array3 = array('a', '1 ...