随笔分类 - Codewars notes
Notes for Codewars.
摘要:Exercise: Solution: 1. def remove_char(s): s1 = list(s)#把字符串 拆分成列表 s1.remove(s1[0])#删除列表第一个元素 s1.pop()#删除列表最后一个元素 #把新生成的列表 s1 生成字符串 s2 = '' for i in s
阅读全文
摘要:Exercise: Solution: 1. def rental_car_cost(d): pd = 40 * d if d < 3: return pd elif d < 7: return pd - 20 else: return pd - 50 2. def rental_car_cost(
阅读全文
摘要:Codewars exercise: Solution: def feast(beast, dish): return beast.startswith(dish[0]) & beast.endswith(dish[-1])
阅读全文
摘要:exercise: Given a string of digits, you should replace any digit below 5 with '0' and any digit 5 and above with '1'. Return the resulting string. Not
阅读全文
摘要:def double_char(s): s2 = '' for i in s: i += i s2 += i return s2 *replace()函数 *tanslate()-str.maketrans(oldstr, newstr, delstr)
阅读全文
摘要:Write a function to convert a name into initials. This kata strictlytakes two words with one space in between them.The output should be two capital le
阅读全文
摘要:title(): Python title() 方法返回"标题化"的字符串,就是说所有单词都是以大写开始 语法: str.title() 返回值: 所有单词都是以大写开始 例: istitle(): 简介: 检测字符串中的 单词 拼写 首字母是否大写 且 其他字母小写 语法: str.istitle
阅读全文
摘要:DNA 到 RNA 的转换 脱氧核糖核酸,DNA是生物系统中主要的信息存储分子。它由四个核酸碱基鸟嘌呤 ('G')、胞嘧啶 ('C')、腺嘌呤 ('A') 和胸腺嘧啶 ('T') 组成。 核糖核酸(RNA)是细胞中的主要信使分子。RNA 与 DNA 的化学结构略有不同,不含胸腺嘧啶。在 RNA 中,
阅读全文
摘要:Solution : def find_smallest_int(arr): select = min(arr) return select find_smallest_int([78, 56, 232, 12, 11, 43]) find_smallest_int([78, 56, -2, 12,
阅读全文
摘要:def digitize(num): lst = str(num)[-1::-1] # 数字转换成 字符串 然后 倒序 lst2 = [int(x) for x in lst] #把字符串 格式 强制转换成 int型 输出到列表li s return lst2 digitize (35231) di
阅读全文
摘要:利用 list() 方法,默认把空格、逗号等所有符号在内的每一个字符串元素逐个打印,分别作为列表的每个元素: s = '8, 3, 2, 7, 1' l = list(s) print(l) 输出:['8', ',', ' ', ' ', ' ', '3', ',', ' ', '2', ',',
阅读全文
摘要:Python中有split()和os.path.split()两个函数,具体作用如下: split():拆分字符串。通过指定分隔符对字符串进行切片,并返回分割后的字符串列表(list)os.path.split():按照路径将文件名和路径分割开 一、函数说明1、split()函数语法:str.spl
阅读全文
摘要:python 字符串切片 语法格式:str[开始位置:结束位置:步长] 结果:[开始字符,..... ,结束字符] /不含头尾 参考:https://blog.csdn.net/weixin_46689301/article/details/123866652
阅读全文
摘要:Solution def smash(words): sentence = "" for i in words: sentence = sentence + ' ' + i #在每个单词前加一个空格 return sentence.strip(' ') #strip('a') 去掉字符串首尾的 字符
阅读全文
摘要:Solution: def reverse_seq(n): lst = [] for i in range(n, 0, -1): lst.append(i) return lst #这里用 print(lst)输出显示一样,但是结果和答案不同:print和return 的值不同 reverse_se
阅读全文
摘要:def make_negative( number ): if number > 0: return number * -1 else: return number make_negative(1) make_negative(-5) make_negative(0)
阅读全文
摘要:Sample tests import codewars_test as test from solution import find_average @test.describe("Fixed Tests") def fixed_tests(): @test.it('Basic Test Case
阅读全文
摘要:>>: Given a set of numbers, return the additive inverse of each. Each positive becomes negatives, and the negatives become positives. invert([1,2,3,4,
阅读全文