小编Ter*_*how的帖子

a.insert(0,x)是o(n)函数吗?是否支持O(1)功能?蟒蛇

我试图将数组中的偶数移到前面,将奇数移到数组的后面.该问题要求在线性算法中执行此操作并在此处执行此操作.

我想出了这个:

 def sort(a):
    for i in range(0,len(a)-1):
        if a[i]%2==0:
            a.insert(0,a.pop(i))
    return a
Run Code Online (Sandbox Code Playgroud)

问题是,有人告诉我,技术上,a.insert是一个o(n)函数,所以从技术上讲,这将被认为是非线性算法(当包括for i in range函数的一部分时).由于提出这个问题的论坛已经有几个月了,我无法要求解释.

基本上我相信他说"技术上",因为因为它在前面插入它,它不会检查数组中的另外N个元素,因此使其在O(n)而不是O(n ^ 2)的实际用途中运行.这是正确的评估吗?

此外,论坛上有人用于a.append修改上述内容并将其更改为查找奇数.没有人回答所以我想知道,是否a.append不是o(n)函数,因为它将它移动到最后?是o(1)?

感谢您的解释和澄清!

python list insertion

1
推荐指数
2
解决办法
788
查看次数

int转换运算符'类后跟int是非法的'返回类型的main应该是'int'而不是'class'

我现在正在从一本书中自学C++,其中一个练习是编写一个类Date,它将它保存的日期转换为一个唯一的整数.但是,当我运行程序时,我无法弄清楚我得到的这个错误.我在C++ 2010上编程.

错误是:

error C2628: 'Date' followed by 'int' is illegal (did you forget a ';'?)

error C3874: return type of 'main' should be 'int' instead of 'Date'

奇怪的是我试图将我的主要改为"返回0"; 并且仍然会出现上述错误.有任何想法吗?

这是我的代码:

#include "stdafx.h"
#include <iostream>

using namespace std;



class Date{
private:
    int day, month, year; //declaring variables

public:

    //declare constructor
    Date(int inputDay=1, int inputMonth=1, int inputYear=2012)
    :day(inputDay), month(inputMonth),year(inputYear){};

    // declare conversion operator for integers
    operator int(){
        return year*10000+month*100+day;
    }
}



int main() {
    Date today(25,11,2012);
    return today;
    //doesn't matter if …
Run Code Online (Sandbox Code Playgroud)

c++

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

有没有办法在Python中寻找特定的行?

我正在自学编程,今天的挑战是编写一个可以左右对齐文本的程序.我的主要问题是,一旦我打开文件,我不知道如何写入特定的行.是否有捷径可寻?这就是我所拥有的.我想我将需要以某种方式计算行中的字节,以便我可以f.seek到行的末尾.我觉得python已经在某个地方有这种类型的功能,但我找不到它在线搜索.有什么建议?

def align():
    name= input('what is the name of your txt file?: ')
    try:
        f=open(name + '.txt','r+')
        lines =f.readlines()
        just = input('left, right, or centre?: ')
        for i in range[,lines]:
            j = lines[i].strip('\n')
            if just == 'right':
                f.seek() #I want it to seek each line but can't figure out what variable might go here...
                f.write('{:>30}'.format(line.strip()))
            elif just == 'left':
                f.seek() #I want it to seek each line but can't figure out what variable might go here...
                f.write('{:<30}'.format(line.strip()))
                f.seek() #I want …
Run Code Online (Sandbox Code Playgroud)

python

0
推荐指数
1
解决办法
164
查看次数

如何使用脚本批量更改Amazon S3中的文件夹名称

我上传了一堆图像,但不小心将文件夹命名为空格。现在您无法访问它们,因为网址显然不能有空格。

我已经下载了aws cli,想知道如何更改文件夹名称?我查看了文档,但仍然遇到麻烦,希望有人可以提供帮助。

我尝试了以下命令,但未成功:

aws s3 mv "s3://mybucketname/firstfolder/second folder with spaces/" s3://mybucketname/firstfolder/secondfolderwithspaces/ --recursive

如何将“带空格的第二个文件夹”的名称更改为“ secondfolderwithspaces”?

另外,有没有办法可以遍历这些文件夹?就像是

for folder in s3:/bucketname/firstfolder: 
     aws s3 mv "folder with spaces" folderwithspaces --recursive
Run Code Online (Sandbox Code Playgroud)

unix amazon-s3 amazon-web-services aws-cli

0
推荐指数
1
解决办法
1256
查看次数

Font Awesome 4.1.0无法在Cordova android模拟器中工作

我无法弄清楚为什么Font Awesome图标没有显示在我的cordova应用程序中.

我下载了整个font-awesome文件夹并将其复制到我项目的文件夹中.我已经包含了以下文件夹:

<link rel="stylesheet" href="../font-awesome-4.1.0/css/font-awesome.min.css">

我确信这是正确的,因为<i class="fa fa-bars fa-2x"></i>在chrome中显示完全正常.

但是,当我运行cordova emulate android图标时,我的android模拟器中没有显示.

然后我尝试按照这里的故障排除:https://github.com/FortAwesome/Font-Awesome/wiki/Troubleshooting

似乎故障排除认为这是一个错误相关text-rendering,但当我添加text-rendering: auto;.fa { }minified和完整的CSS时,我仍然没有在我的Android模拟器中看到图标.

我不知道该怎么办.我的android目标项目是4.4.2 api等级19.任何人都可以帮忙吗?

这是与图标相关的html部分.

<body> 
    <div id="main">
           <div id="top">
               <i id="settings" class="fa fa-bars fa-2x"></i>
               <p id="logo" > Chowza Inc </p>
          </div>
    </div>
...
</body>
Run Code Online (Sandbox Code Playgroud)

css fonts android cordova font-awesome

0
推荐指数
1
解决办法
5454
查看次数

无法使ScrollMagic parralax补间工作

我正在尝试实现第一个示例中的代码:

http://janpaepke.github.io/ScrollMagic/examples/advanced/parallax_scrolling.html

以下补间工作(但立即补间)...

var tween = new TimelineMax().add([
        TweenMax.to('#test',1,{top:"50%",ease:Linear.easeNone})
    ]);
Run Code Online (Sandbox Code Playgroud)

当我添加以下代码时......

var scene = new ScrollMagic.Scene({
    triggerElement:'#test' ,
    duration:500
})
    .setTween(tween)
    .addTo(controller);
Run Code Online (Sandbox Code Playgroud)

我得到以下错误:

Uncaught TypeError: (intermediate value).setTween is not a function

我疯了,试图解决这个问题.我究竟做错了什么?

scrollmagic

0
推荐指数
1
解决办法
3923
查看次数

结合密码中的属性

我想使用cypher返回某种形式的东西:

{
  name: 'Name of Parent Node',
  property1 : 'some property of parent node',
  property2 : 'some other property'
  children: [...some array of children...]
}
Run Code Online (Sandbox Code Playgroud)

到目前为止,我已经完成了以下工作:

MATCH (p:Parent)-[:SOME_RELATIONSHIP]->(c:Child)
WITH collect(c) as children, p
RETURN {properties: properties(p),  children: children} 
Run Code Online (Sandbox Code Playgroud)

哪种有点类似于我想要的,但不完全相同。有没有一种方法可以将其合并或合并,以使属性组合在一起?

neo4j cypher

0
推荐指数
1
解决办法
347
查看次数

具有结构指针返回值的 func 与具有接口指针返回值的 func 不匹配。可以以某种方式编译吗?

有一些生成的代码我无法更改。它们的一般结构如下:

// These structures & methods I cannot change

type NotMyStruct struct {
    EmbeddedCaller
}
type EmbeddedCaller struct {
    foobar string
}

func (_embeddedCaller *EmbeddedCaller) DoStuff() string {
    return "ABC"
}

func NewNotMyStruct() *NotMyStruct {
    return &NotMyStruct{
        EmbeddedCaller{"blah"},
    }
}

Run Code Online (Sandbox Code Playgroud)

生成代码的一般模式是 1) 父结构 + 嵌入结构 2) 嵌入结构上的方法 3) 创建该结构的 New 方法。

我有许多生成的“合同”,它们都有不同的类型,即 NotMyStruct1 NotMyStruct2 等。嵌入的结构也都是不同的类型,即 EmbeddedCaller1、EmbeddedCaller2 等。

然而它们都有相同的方法 DoStuff 和相同的返回值。我想做的是创建一些 id 到 New 函数的映射,然后迭代每个函数并调用 DoStuff 方法。但是我的代码无法编译。如果编译它会看起来像这样:

type MyDoStuffInterface interface {
    DoStuff() string
}
var instantiations map[string]func()*MyDoStuffInterface{
    "1": NewNotMyStruct, //<-- does …
Run Code Online (Sandbox Code Playgroud)

go

0
推荐指数
1
解决办法
61
查看次数