Codewars-python 20190117
9483 ワード
1.Descending Orders input:324189 output:984321知識点:’.join[:-1]:list逆配列
2.Your Order,please input:“is 2 Thi 1 s T 4 est 3 a”output:“Thi 1 s is 2 3 a T 4 est”方法一:
方法2:
3.Mumbling input:“abcd”output:“A-Bb-Ccc-ddd”自分の方法:
大神の作り方:
4.Find the next perfect square!
def Descending_Order(num):
#Bust a move right here
num = list(str(num))
return int(''.join(sorted(num)[::-1]))
2.Your Order,please input:“is 2 Thi 1 s T 4 est 3 a”output:“Thi 1 s is 2 3 a T 4 est”方法一:
def order(sentence):
# code here'
sentence = sentence.split()
Arr = ['']*len(sentence)
for s in sentence:
for c in s:
if c.isdigit(): #
Arr[ord(c)-ord('1')] = s
break
return ' '.join(Arr)
方法2:
def order(words):
return ' '.join(sorted(words.split(), key=lambda w:sorted(w)))
3.Mumbling input:“abcd”output:“A-Bb-Ccc-ddd”自分の方法:
def accum(s):
s = list(s)
result = []
reslut1 = []
for i in range(len(s)):
result.append((i+1)*s[i])
for j in result:
j = j.capitalize()
result1.append(j)
return str('-'.join(result1))
大神の作り方:
def accum(s):
return '-'.join(c.upper()+c.lower()*i for i, c in enumerate(s))
4.Find the next perfect square!
import math
def find_next_square(sq):
# Return the next square if sq is a square, -1 otherwise
a = math.sqrt(sq)
if a - int(a) > 0:# int
return -1
else:
return int(pow((a+1),2))