小编Tom*_*tah的帖子

找到与给定数字相乘的数字的有效方法

我得到了2列表,a并且b. 它们都只包含整数。min(a) > 0max(a)可高达1e10并且max(abs(b))可高达1e5。我需要找到元组的数量(x, y, z),其中的x位置ay, z位置是b这样的x = -yza和 中的元素数b最多可达1e5

我的尝试:

我能够想出一个天真的n^2算法。但是,由于大小可以达到 1e5,因此我需要提出一个nlogn解决方案 (max)。我所做的是:

  1. 拆分bbpbn,其中第一个包含了所有的正数和第二个包含所有的负数,并创建自己的地图。

  2. 然后:

    2.1 我迭代a得到x的。

    2.2遍历的较短一个bnbp。检查当前元素是否除x。如果是,则用于map.find()查看是否z = -x/y存在。

有什么有效的方法可以做到这一点?

c++ arrays algorithm data-structures

7
推荐指数
1
解决办法
326
查看次数

如何整理参数功能以从枚举创建一组值?

给定一个Enum无法修改的对象,以及一个自定义Query类,该类应该生成Enum给定不同参数的值的编译:

from enum import Enum

class Fields(Enum):
    a = ["hello", "world"]
    b = ["foo", "bar", "sheep"]
    c = ["what", "the"]
    d = ["vrai", "ment", "cest", "vrai"]
    e = ["foofoo"]

class Query:
    def __init__(self, a=True, b=True, c=False, d=False, e=False):
        self.query_fields = set()
        self.query_fields.update(Fields.a.value) if a else None
        self.query_fields.update(Fields.b.value) if b else None
        self.query_fields.update(Fields.c.value) if c else None
        self.query_fields.update(Fields.d.value) if d else None
        self.query_fields.update(Fields.e.value) if e else None
Run Code Online (Sandbox Code Playgroud)

可以获得一组自定义的query_fields,例如:

[出去]:

>>> x = Query() …
Run Code Online (Sandbox Code Playgroud)

python enums class object set

7
推荐指数
1
解决办法
330
查看次数

从 Java 8 到 Java 11 的迁移中单元测试失败

我正在努力将我的项目从 Java 8 迁移到 Java 11。所以我使用了 Spring 5.1.0、Java 11、Eclipse 4.16 和 Tomcat 9。我能够成功构建源代码。但当谈到测试时,他们却失败了。

这是我在 pom.xml 中进行测试的内容。

<dependency>
   <groupId>junit</groupId>
   <artifactId>junit</artifactId>
   <version>4.12</version>
   <scope>test</scope>
   <type>jar</type>
</dependency>
<dependency>
   <groupId>org.mockito</groupId>
   <artifactId>mockito-core</artifactId>
   <version>2.27.0</version>
   <scope>test</scope>
</dependency>
<dependency>
   <groupId>org.powermock</groupId>
   <artifactId>powermock-module-junit4</artifactId>
   <version>2.0.2</version>
   <scope>test</scope>
</dependency>
<dependency>
   <groupId>org.powermock</groupId>
   <artifactId>powermock-api-mockito2</artifactId>
   <version>2.0.2</version>
   <scope>test</scope>
</dependency> 
Run Code Online (Sandbox Code Playgroud)

我的测试用例在 Java 8 中的上述依赖关系下运行得非常好。但是当我将代码迁移到 Java 11 时,我遇到了以下异常。

ERROR: org.springframework.test.context.TestContextManager - Caught exception while allowing 
TestExecutionListener 
[org.springframework.test.context.support.DependencyInjectionTestExecutionListener@54e063d] to 
prepare test instance [com.test.SomeTest2@4293943]

java.lang.IllegalStateException: Failed to load ApplicationContext
at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:122) ~[Spring-test-5.1.0.RELEASE.JAR:5.1.0.RELEASE]
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DefaultTestCDependencyInjectionTestExecutionListenerontext.java:122) ~[Spring-test-5.1.0.RELEASE.JAR:5.1.0.RELEASE]
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DefaDefaultTestCDependencyInjectionTestExecutionListenerontextultTestContext.java:122) ~[Spring-test-5.1.0.RELEASE.JAR:5.1.0.RELEASE]
at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:312) ~[Spring-test-5.1.0.RELEASE.JAR:5.1.0.RELEASE]
at …
Run Code Online (Sandbox Code Playgroud)

java eclipse junit classpath maven

6
推荐指数
1
解决办法
3456
查看次数

如何在Scala中减去列表中的两个连续元素?

我想在 Scala 中用数字减去列表中的两个连续元素。

例如:我有这个清单:

val sortedList = List(4,5,6)
Run Code Online (Sandbox Code Playgroud)

我想要一个输出列表,比如diffList =(1, 1)where5-4 = 16-5 = 1

我尝试了以下代码:

var sortedList = List[Int]()
var diffList = List[Int]()

for (i <- 0 to (sortedList.length - 1) ;j <- i + 1 to sortedList.length - 1) 
{
    val diff = (sortedList(j) - sortedList(i))
    diffList = diffList :+ diff
}
Run Code Online (Sandbox Code Playgroud)

我有以下结果,diffList =(1, 2, 1)但我想要diffList = (1,1).

这是因为for循环。它不会一次迭代两个变量(i 和 j)。

scala list

6
推荐指数
3
解决办法
420
查看次数

如何使用 Selenium 在 Youtube 上发表评论

我正在尝试使用 Selenium 在 Youtube 上发表评论。以下是代码的要点(关于登录谷歌的那几行省略了):

comment_url = "https://www.youtube.com/all_comments?v=LAr6oAKieHk"
profile = webdriver.FirefoxProfile()
driver = webdriver.Firefox(firefox_profile=profile)

driver.get(comment_url)
assert "All comments" in driver.title

textbox = driver.find_element_by_class_name("box")
textbox.click()
textbox.send_keys("My comment")
Run Code Online (Sandbox Code Playgroud)

textbox.click()按预期工作并将焦点设置到评论框。但是,textbox.send_keys("My comment")不会将文本输入框中,而是以某种方式使焦点偏离。

任何人都可以提出任何建议吗?

python youtube selenium selenium-webdriver

5
推荐指数
1
解决办法
3656
查看次数

手动排除 sbt 中的一些测试类

我通常在我的 CI 中执行以下命令:

干净更新编译测试发布

但是,我想从 sbt 命令行中排除 1 个(或几个)测试类。

我怎样才能做到这一点?(我不想更改我的代码以使用忽略等)

scala sbt scalatest

5
推荐指数
2
解决办法
4569
查看次数

导入 sbt 项目时提取结构失败

我正在尝试在 IntelliJ IDE 上设置 Scala,当我创建一个新项目时,它看起来很好。当我导入另一个项目时,它会出错:Extracting Structure Failed.

sbt shell 似乎在工作。可能是什么问题?

这是我的build.sbt

course := "progfun1"
assignment := "example"
scalaVersion := "2.12.12"
scalacOptions ++= Seq("-language:implicitConversions", "-deprecation")
libraryDependencies += "com.novocode" % "junit-interface" % "0.11" % Test 
testOptions in Test += Tests.Argument(TestFrameworks.JUnit, "-a", "-v", "-s")
Run Code Online (Sandbox Code Playgroud)

这是日志:

2020-10-17 16:45:29,222 [      0]   INFO -        #com.intellij.idea.Main - ------------------------------------------------------ IDE STARTED ------------------------------------------------------ 
2020-10-17 16:45:29,291 [     69]   INFO -        #com.intellij.idea.Main - IDE: IntelliJ IDEA (build #IC-202.7660.26, 06 Oct 2020 11:32) 
2020-10-17 16:45:29,292 [     70]   INFO …
Run Code Online (Sandbox Code Playgroud)

scala intellij-idea sbt

5
推荐指数
1
解决办法
4483
查看次数

无法在 label-studio 中添加 Ml 后端

我正在尝试在 label studio 上添加我的 ML 模型。我已经尝试过这些命令

cd label-studio
pip install -e .
cd label_studio/ml/examples
pip install -r requirements.txt


   label-studio-ml init my_ml_backend --script label_studio/ml/examples/simple_text_classifier.py
Run Code Online (Sandbox Code Playgroud)

这些是 label_studio/ml/examples 中的文件:-requirements.txt

simple_text_classifier.py

dummy_model.py

pytorch_transfer_learning.py
Run Code Online (Sandbox Code Playgroud)

它给了我这个错误:

ModuleNotFoundError: No module named 'simple_text_classifier'
Run Code Online (Sandbox Code Playgroud)

如何在 label studio 上添加我的模型?

python machine-learning

5
推荐指数
1
解决办法
2643
查看次数

简化 Scala 中的 Option[Boolean] 表达式

我有这样的代码:

optionBoolean.getOrElse(false) && otherOptionBoolean.getOrElse(false)
Run Code Online (Sandbox Code Playgroud)

Scalastyle 告诉我它可以简化。如何?

boolean-logic scala optional scalastyle scala-option

5
推荐指数
1
解决办法
277
查看次数

KQL,同一个表中不同行之间的时间差

我有Sessions桌子

Sessions
|Timespan|Name |No|
|12:00:00|Start|1 |
|12:01:00|End  |2 |
|12:02:00|Start|3 |
|12:04:00|Start|4 |
|12:04:30|Error|5 |
Run Code Online (Sandbox Code Playgroud)

我需要使用 KQL 从中提取每个会话的持续时间(但如果您能给我建议如何使用其他查询语言来做到这一点,那也会非常有帮助)。但如果后面的下一行start也是start,则意味着会话被放弃,我们应该忽略它。

预期结果:

|Duration|SessionNo|
|00:01:00|    1    |
|00:00:30|    4    |
Run Code Online (Sandbox Code Playgroud)

kql azure-data-explorer

5
推荐指数
1
解决办法
5384
查看次数