计算一个数组的中间数,数的两边和相等,并返回index值 如:数组[1,2,3,4,6] 返回3(数组序号从0开始) def find_even_index(arr): """找到数组中间数,左右两边数相等""" for x in range(len(arr)-1): if sum(arr)-arr[x]==2*sum(arr[:x]): return x if x==len(arr): return -1…
list中保留四字母的,然后return. 解 def friend(x): i = len(x) ii = [] a = 0 while a < i: if len(x[a]) == 4: ii.append(x[a]) a += 1 return ii 别人的超pythonic的题解.. def friend(x): return [f for f in x if len(f) == 4]…
http://jasonjl.me/blog/2015/03/30/practical-programming-practice-services/ Codewars, Leetcode, Hackerrank. Online Judges Reviews written March 30, 2015 in algorithms, programming, review Sometimes the projects you work on just aren’t stimulating enou…
说明:以下内容均来自codewars网站,列举的试题我都做过且通过,并以此记录来学习python. 1,需求:将大小写互相转换,非字母的字符保留 我的代码: def to_alternating_case(string): #your code here result = '' for i in range(len(string)): if string[i].isupper(): result += string[i].lower() elif string[i].islower(): r…
@Codewars Python练习 question ** Dashatize it ** Given a number, return a string with dash'-'marks before and after each odd integer, but do not begin or end the string with a dash mark. Ex: dashatize(274) -> '2-7-4' dashatize(6815) -> '68-1-5' soluti…
@Codewars Python练习 question ** Simple transposition ** Simple transposition is a basic and simple cryptography technique. We make 2 rows and put first a letter in the Row 1, the second in the Row 2, third in Row 1 and so on until the end. Then we put…