Python-CodeWars-17-11-26
来源:互联网 发布:网络安全工程师怎么考 编辑:程序博客网 时间:2024/05/22 14:35
CodeWars-1126
# -*- coding: utf-8 -*-# @Time : 2017/11/26 上午11:59# @Author : SkullFang# @Email : yzhang.private@gmail.com# @File : 11-26.py# @Software: PyCharmimport mathdef remove_char(s): if len(s)>2 : return s[1:-1] else: return '' #your code here"""def remove_char(s): return '' if len(s) <= 2 else s[1:-1]"""def find_next_square(sq): num=int(math.sqrt(sq)) if num**2 == sq: return (num+1)**2 # Return the next square if sq is a square, -1 otherwise return -1# print(find_next_square(121))"""bestdef find_next_square(sq): root = sq ** 0.5 if root.is_integer(): #判断是不是一个整数 return (root + 1)**2 return -1"""def divisors(integer): li=[i for i in range(2,integer) if integer%i==0] if li: return li return '{0} is prime'.format(integer) pass# print(divisors(13))"""best is me"""def make_negative( number ): return number if number<=0 else 0-number# print(make_negative(0))"""best is me"""def duplicate_count(text): text=text.lower(); li=[] cn=0; for i in range(0,len(text)): subli=text[i+1:] if text[i] in subli: if text[i] not in li: li.append(text[i]) cn+=1 return cn # Your code goes here# print(duplicate_count("aA11"))"""bestdef duplicate_count(s): return len([c for c in set(s.lower()) if s.lower().count(c)>1])"""def high_and_low(numbers): li=numbers.split(" ") re=[int(i) for i in li] max_number=max(re) min_number=min(re) numbers=str(max_number)+" "+str(min_number) return numbers# print(high_and_low("4 5 29 54 4 0 -214 542 -64 1 -3 6 -6"))""""""def unique_in_order(iterable): li=list(iterable) re=[] if li: re.append(li[0]) for i in range(1,len(li)): if li[i]!=li[i-1]: re.append(li[i]) return re# print(unique_in_order('A'))def reverse_seq(n): return list(reversed([i for i in range(1,n+1)])) pass# print(reverse_seq(5))def no_space(x): li=x.split(" ") re=[_ for _ in li if _ !=''] # print(re) return ''.join(re) #your code hereprint(no_space('8 j 8 mBliB8g imjB8B8 jl B'))
总结:
1、判断一个数是不是整数可以用 is_interger()方法。
2、把列表转换为字符串可以用 ‘’.join(list)
3、字符串的分割用string.split(” “)
阅读全文
0 0
- Python-CodeWars-17-11-26
- CodeWars---Python第二题
- CodeWars---Python第三题
- CodeWars---Python第四题
- 【Codewars-求矩阵行列式】python
- 【Codewars-snail】顺时针打印矩阵(python)
- daily CodeWars
- Part2.CodeWars
- codewars day1
- 【codewars】Mumbling
- codewars - Broken Greetings
- CodeWars——js
- Codewars 9月刷题
- 【Codewars-hamming(汉明数)】
- LeetCode & Codewars 食用口感
- CodeWars 编解码问题
- [Haskell] CodeWars|Printer Errors
- [Haskell] CodeWars|Vowel Count
- Ubuntu上安装MySQL
- 20171127
- vmstat
- 1
- 使用纹理制作特效
- Python-CodeWars-17-11-26
- 【Scikit-Learn 中文文档】流形学习
- CSS background-position属性
- java内部类
- Android的mipmap和drawable的区别和使用
- php中的数组
- MediaCodec基础入门
- MyBatis之全局配置文件(Configuration XML)之typeAliases别名
- 欢迎使用CSDN-markdown编辑器