(数组[i] ==; 1)比Python中的(array [i] ==')快的速度更快?
使用
if(array[i]=="1")
所有测试用例(以黑客等级为单位)。
但是
if(array[i]=='1')
没有通过所有测试用例。
“”
和''
之间有什么区别?
为什么后者需要更多时间?
这是屏幕截图:
代码:错误:
#!/bin/python3
import math
import os
import random
import re
import sys
#
# Complete the 'acmTeam' function below.
#
# The function is expected to return an INTEGER_ARRAY.
# The function accepts STRING_ARRAY topic as parameter.
#
def acmTeam(topic):
m=0
count=0
for i in range(len(topic)):
for j in range(i+1,len(topic)):
k=(bin(int(topic[i],2) | int(topic[j],2)))[2:]
# if k>m:
# m=k
# count=1
# elif m==k:
# count+=1
val=0
for ind in range(len(k)):
if (k[ind]=="1"):
val+=1
if val>m:
count=1
m=val
elif val==m:
count+=1
return [m,count]
Using
if(array[i]=="1")
passes all test cases (in Hacker rank).
But
if(array[i]=='1')
doesn't pass all the test cases.
What are the differences between ""
and ''
in Python?
Why does the latter take more time?
Here are the screenshots:
The code:
#!/bin/python3
import math
import os
import random
import re
import sys
#
# Complete the 'acmTeam' function below.
#
# The function is expected to return an INTEGER_ARRAY.
# The function accepts STRING_ARRAY topic as parameter.
#
def acmTeam(topic):
m=0
count=0
for i in range(len(topic)):
for j in range(i+1,len(topic)):
k=(bin(int(topic[i],2) | int(topic[j],2)))[2:]
# if k>m:
# m=k
# count=1
# elif m==k:
# count+=1
val=0
for ind in range(len(k)):
if (k[ind]=="1"):
val+=1
if val>m:
count=1
m=val
elif val==m:
count+=1
return [m,count]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
没有区别。
如果我们查看使用
dis
软件包比较单引号与双引号的比较的字节码:单引号
双引号
python的词汇分析过程,
使用Python's <代码> AST 模块,我们可以在编译之前先查看代码。
单引号
双引号
结论
可能是Python评估器中的错误。
该代码无论哪种方式都是完全相同的,并且没有真正的方法知道这是否是巧合的,而无需检查口译员C实现的最后一个细节。
There's no difference.
If we view the bytecode for comparing single quoted vs double quoted comparisons using the
dis
package:Single Quoted
Double Quoted
Python's lexical analyzation process
Using Python's
ast
module, we can look at our code before it's compiled.Single Quoted
Double Quoted
Conclusion
Probably an incorrect bit in Python's evaluator.
The code is the exact same either way, and there's no real way of knowing if this is coincidence without inspecting every last detail of the interpreter's C implementation.
我不知道为什么会发生,另一个会发生。每次执行的时间都不同。
关于双人行情,在python中没有差异,您可以在无数的网页中找到它。不幸的是,我在官方页面上找不到它, http://www.python.org/
I don't know why one happens and the other doesn't. The times vary in each execution.
Regarding the double and single quotes, in python there are no differences, you can find this in countless web pages. Unfortunately I couldn't find it on the official page http://www.python.org/