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) + ...
随机推荐
- IE6下javascript:void(0)不可用的解决
<a href="javascript:void(0)" class="inp_sear_a" onclick="doSubmit();&quo ...
- golang 切片和数组在for...range中的区别
切片是引用类型,而数组是值类型,并且for...range有以下规则: range表达式只会在for语句开始执行时被求值一次,无论后边会有多少次迭代 range表达式的求值结果会被复制,也就是说,被迭 ...
- Tornado初探
Tornado 是 FriendFeed 使用的可扩展的非阻塞式 web 服务器及其相关工具的开源版本.这个 Web 框架看起来有些像web.py 或者 Google 的 webapp,不过为了能有效 ...
- Centos Android开发环境配置-Android Tools -android list sdk --extended --all
Centos Android开发环境配置-Android Tools -android list sdk --extended --all 安装完Android Tools后执行 android ...
- asp.net core中遇到需要自定义数据包解密方法的时候
最近将公司的项目用.netcore重写, 服务的http外部接口部分收发消息是DES加解密的, 那么在asp.net core mvc的action处理之前需要加入解密这个步骤. 我第一想到的是用fi ...
- @JSONField注解的使用
FastJson中的注解@JSONField,一般作用在get/set方法上面,常用的使用场景有下面三个: 修改和json字符串的字段映射[name] 格式化数据[format] 过滤掉不需要序列化的 ...
- atexit()使用
mian()主函数执行完毕后,是否可能会再执行一段代码?如果需要加入一段代码在mian退出后执行的代码,可以使用atexit()函数注册一个函数,代码如下: #include <iostream ...
- Jmeter之分布式执行测试
一. 安装Java 1.1下载JDK 1) Windows安装jdk,下载完成后,双击安装 2) Linux解压:tar -zxvf jdk-8u74-linux-x64.gz 1.2 Java环境变 ...
- Intellij添加Jetty远程Debug
步骤一: 步骤二: 步骤三:-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=15005 步骤四: 找到服务器上jetty的b ...
- MYSQL 的静态表和动态表的区别, MYISAM 和 INNODB 的区别
MyISAM是MySQL的默认数据库引擎(5.5版之前),由早期的ISAM(Indexed Sequential Access Method:有索引的顺序访问方法)所改良.虽然性能极佳,但却有一个缺点 ...