Code Signal_练习题_variableName
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 bevariableName(name) = true
; - For
name = "qq-q"
, the output should bevariableName(name) = false
; - For
name = "2w2"
, the output should bevariableName(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的更多相关文章
- Code Signal_练习题_digitDegree
Let's define digit degree of some positive integer as the number of times we need to replace this nu ...
- Code Signal_练习题_Knapsack Light
You found two items in a treasure chest! The first item weighs weight1 and is worth value1, and the ...
- Code Signal_练习题_growingPlant
Each day a plant is growing by upSpeed meters. Each night that plant's height decreases by downSpeed ...
- Code Signal_练习题_arrayMaxConsecutiveSum
Given array of integers, find the maximal possible sum of some of its k consecutive elements. Exampl ...
- Code Signal_练习题_differentSymbolsNaive
Given a string, find the number of different characters in it. Example For s = "cabca", th ...
- Code Signal_练习题_firstDigit
Find the leftmost digit that occurs in a given string. Example For inputString = "var_1__Int&qu ...
- Code Signal_练习题_extractEachKth
Given array of integers, remove each kth element from it. Example For inputArray = [1, 2, 3, 4, 5, 6 ...
- Code Signal_练习题_stringsRearrangement
Given an array of equal-length strings, check if it is possible to rearrange the strings in such a w ...
- 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) + ...
随机推荐
- C++类和对象(一)&&实现offsetof宏&&this指针
一.目录 1.对象的相关知识 2.类的定义 3.类的实例化 4.类对象模型 5.模拟实现offsetof宏 6.this指针 二.正文 1.对象的相关知识 C语言是面向过程的,关注的是过程,分析求解问 ...
- Runtime 全方位装逼指南
Runtime是什么?见名知意,其概念无非就是“因为 Objective-C 是一门动态语言,所以它需要一个运行时系统……这就是 Runtime 系统”云云.对博主这种菜鸟而言,Runtime 在实际 ...
- QQ gtk,bkn算法
public long GetGTK(string sKey) { ; , len = sKey.Length; i < len; ++i) { hash += (hash << ) ...
- asp.net core 系列之用户认证(1)-给项目添加 Identity
对于没有包含认证(authentication),的项目,你可以使用基架(scaffolder)把 Identity的程序集包加入到项目中,并且选择性的添加Identity的代码进行生成. 虽然基架已 ...
- 转载:Java、C#双语版配套AES加解密示例
转载,原文出处 http://www.cnblogs.com/lzrabbit/p/3639503.html 这年头找个正经能用的东西那是真难,网上一搜索一大堆,正经能用的没几个,得,最后还是得靠自己 ...
- ActiveMQ配置高可用性的方式
当一个应用被部署于生产环境,灾备计划是非常重要的,以便从网络故障,硬件故障,软件故障或者电源故障中恢复.通过合理的配置ActiveMQ,可以解决上诉问题.最典型的配置方法是运行多个Broker,一旦某 ...
- Android_EditText 密码框默认是小圆点 怎么改成其它的(*)?
text.setTransformationMethod(new AsteriskPasswordTransformationMethod()); public class AsteriskPassw ...
- win10上Tensorflow的安装教程
这几天打算自己入门学习机器学习的内容,首先要安装Tensorflow. 自己捣鼓了几天才捣鼓出来.可能真的是比较笨orz 现在试试写一个教程,希望可以帮到迷路滴孩子们! 大体地说四步: 安装pytho ...
- scala-03-list操作
列表 Scala 列表类似于数组,它们所有元素的类型都相同,但是它们也有所不同:列表是不可变的,值一旦被定义了就不能改变,其次列表 具有递归的结构(也就是链接表结构)而数组不是.. 1, 创建 lis ...
- php实现请求分流
一个请求,同时分发到多个服务器, 正常的是: A ============> B 现在想实现的是: --------------> C A ======> B ----- ...