yexing
发表于 2020-2-28 22:32:20
zltzlt 发表于 2020-2-28 19:34
解答错误
输入:['qaz', 'wsx', 'edc', 'rfv', 'tgb', 'yhn', 'ujm', 'ik', 'pklo', 'ppppppp']
我尽力了{:10_266:},实在找不出bug。
能否给点小提示{:10_266:},如果不违反规则的话
kinkon
发表于 2020-2-28 23:06:51
TJBEST 发表于 2020-2-28 22:24
你这个不对呀,Hello不是同一行的吧,和实例不一样
TJNEST总是能带了不一样的思路,佩服
kinkon
发表于 2020-2-28 23:16:55
zltzlt 发表于 2020-2-28 18:56
解答错误
输入:["Hello", "Alaska", "Dad", "Peace"]
Hello并不是同一行,Dad才对
阴阳神万物主
发表于 2020-2-29 00:08:18
我感觉自称无脑解的那些仿佛在特意逗我笑。
dic = str.maketrans('qwertyuiopQWERTYUIOPasdfghjklASDFGHJKLzxcvbnmZXCVBNM','1'*20+'2'*18+'3'*14)
solve = lambda lst:
if __name__ == '__main__':
print('示例1 输出:',solve(["Hello", "Alaska", "Dad", "Peace"]))
'''
#草稿在下
def solve(lst:'list of word')->list:
res =
for each in lst:
if len(set(each.lower().translate(dic))) == 1:res.append(each)
return res
'''
kinkon
发表于 2020-2-29 00:23:39
yexing 发表于 2020-2-28 22:32
我尽力了,实在找不出bug。
能否给点小提示,如果不违反规则的话
错在这list1 = s[:]
jdzzj
发表于 2020-2-29 11:03:42
def fun338(words):
result = []
line1 = "qwertyuiop"
line2 = "asdfghjkl"
line3 = "zxcvbnm"
for i in words:
if i.lower() in line1:
if set(i.lower()) <= set(line1):
result.append(i)
elif i.lower() in line2:
if set(i.lower()) <= set(line2):
result.append(i)
elif i.lower() in line3:
if set(i.lower()) <= set(line3):
result.append(i)
yexing
发表于 2020-2-29 13:54:10
zltzlt 发表于 2020-2-28 19:34
解答错误
输入:['qaz', 'wsx', 'edc', 'rfv', 'tgb', 'yhn', 'ujm', 'ik', 'pklo', 'ppppppp']
看看现在还有没有问题
def func338(s:list) -> list:
keyboard = ["qwertyuiop", "asdfghjkl", "zxcvbnm"]
list1 = s[:]
for word_index in s:
string = word_index.lower()
for i in range(len(keyboard)):
if string in keyboard:
index = i
break
for i in string:
if i not in keyboard:
list1.remove(word_index)
break
return list1
yexing
发表于 2020-2-29 13:54:46
kinkon 发表于 2020-2-29 00:23
错在这list1 = s[:]
十分感谢{:10_275:}{:10_275:}
nihaonemo
发表于 2020-2-29 17:16:39
d = ['hello', 'dad','Alask', 'Peace']
class CheckList:
a = 'qwertyuiop'
b = 'asdfghjkl'
c = 'zxcvbnm'
def __init__(self,lst):
self.lst = lst
def check_list(self):
list_b = []
for i in self.lst:
if self.check_word(i) is not None:
list_b.append(i)
return list_b
def check_word(self, word):
list_a = []
for i in word.lower():
if i in self.a:
list_a.append('a')
elif i in self.b:
list_a.append('b')
else:
list_a.append('c')
if len(set(list_a)) == 1:
return word
e = CheckList(d)
print(e.check_list())
nihaonemo
发表于 2020-2-29 17:20:22
d = ['hello', 'dad','Alask', 'Peace']
class CheckList:
a = 'qwertyuiop'
b = 'asdfghjkl'
c = 'zxcvbnm'
def __init__(self,lst):
self.lst = lst
def check_list(self):
list_b = []
for i in self.lst:
if self.check_word(i) is not None:
list_b.append(i)
return list_b
def check_word(self, word):
list_a = []
for i in word.lower():
if i in self.a:
list_a.append('a')
elif i in self.b:
list_a.append('b')
else:
list_a.append('c')
if len(set(list_a)) == 1:
return word
e = CheckList(d)
print(e.check_list())
zltzlt
发表于 2020-2-29 17:33:18
TJBEST 发表于 2020-2-28 22:22
我来晚了,看看速度
161 ms
nihaonemo
发表于 2020-2-29 17:33:37
fan1993423 发表于 2020-2-28 18:06
大佬好 请问 t= " ",t=='' or t=='top'啥意思啊。。。
zltzlt
发表于 2020-2-29 17:34:33
阴阳神万物主 发表于 2020-2-29 00:08
我感觉自称无脑解的那些仿佛在特意逗我笑。
408 ms
zltzlt
发表于 2020-2-29 17:35:53
jdzzj 发表于 2020-2-29 11:03
忘记 return 了
nihaonemo
发表于 2020-2-29 17:37:24
fan1993423 发表于 2020-2-28 18:06
哦 好像懂了
zltzlt
发表于 2020-2-29 17:38:45
yexing 发表于 2020-2-29 13:54
看看现在还有没有问题
输入 ['Python', 'Java', 'C'] * 50000 超时
zltzlt
发表于 2020-2-29 17:40:04
nihaonemo 发表于 2020-2-29 17:20
176 ms
776667
发表于 2020-2-29 17:55:53
本帖最后由 776667 于 2020-2-29 18:02 编辑
def fun338(x):
x = list(set(x))
first_line = 'QWERTYUIOPqwertyuiop'
second_line = 'ASDFGHJKLasdfghjkl'
third_line = 'ZXCVBNMzxcvbnm'
result = []
for i in x:
for j in :
for n in i:
if n not in j:
break
else:
result.append(i)
break
return result
zltzlt
发表于 2020-2-29 18:21:15
776667 发表于 2020-2-29 17:55
输入示例的内容,顺序错了
jdzzj
发表于 2020-2-29 22:12:56
zltzlt 发表于 2020-2-29 17:35
忘记 return 了
手残党,贴代码的时候手残了 {:5_104:}