小编Sar*_*aya的帖子

在dict中找到一个值?

我正在尝试打印出一条消息.如果找不到字典中的单词,那么它应该打印出一条消息而不是给出错误.我的想法是什么

if bool(bool(dictionary[word])) == True:
    return dictionary[word]
else:
    print 'wrong'
Run Code Online (Sandbox Code Playgroud)

但是当我写一些不在字典中的东西时,它不起作用,而是它给出了类似的东西

Traceback (most recent call last):
  File "<pyshell#34>", line 1, in <module>
    translate_word('hous')
  File "H:\IND104\final\Project 4 - Italian-Spanish Translator\trial 1.py", line 21, in translate_word
    if bool(bool(dictionary[word])) == True:
KeyError: 'hous' 
Run Code Online (Sandbox Code Playgroud)

那么如何打印出错误信息谢谢.

python dictionary find

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

按顺序遍历单个链表

我一直在尝试想一种遍历单个链表的方法。

到目前为止,这是我所做的:

#include <iostream>

typedef struct node {                                                               
      int data;               // will store information
      node *next;             // the reference to the next node
};  


int printList(node *traverse) {
    if (traverse->next == NULL) {
        return -1;
    }
    traverse=traverse->next;
    printList(traverse);
    cout << traverse->data << endl;
    return 0;
}

int main() {
    node *head = NULL;      
    for (int i = 0; i < 10; i++) {
        node *newEntry = new node;
        newEntry->data = i;
        newEntry->next = head;
        head = newEntry;
    }
    printList(head);
    return …
Run Code Online (Sandbox Code Playgroud)

c++ traversal linked-list singly-linked-list

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

反向遍历C++中的单链表

最近我在接受采访时被问到了这个问题.我所能做的就是从0到9的链表中从9遍历到1.这是代码:

#include <iostream>

typedef struct node {                                                               
      int data;               // will store information
      node *next;             // the reference to the next node
};  
node *head;

int printList(node *traverse) {
    if (traverse->next == NULL) {
        return -1;
    }
    traverse=traverse->next;
    printList(traverse);

    cout << traverse->data << endl;
    return 0;
}

int main() {
    node *temp = NULL;
    node *begin = NULL;      
    for (int i = 0; i < 10; i++) {
        temp = new node;
        temp->data = i;
        if (begin == NULL) { …
Run Code Online (Sandbox Code Playgroud)

c++ traversal linked-list singly-linked-list

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

ld:找不到架构i386 Xcode单元测试的符号

当我尝试运行单元测试时,我收到此错误.整个错误是:

    Undefined symbols for architecture i386:
  "_CGImageRelease", referenced from:
      _releaseImages in UIImage+animatedGIF.o
  "_CGImageSourceCopyPropertiesAtIndex", referenced from:
      _delayCentisecondsForImageAtIndex in UIImage+animatedGIF.o
  "_CGImageSourceCreateImageAtIndex", referenced from:
      _createImagesAndDelays in UIImage+animatedGIF.o
  "_CGImageSourceCreateWithData", referenced from:
      +[UIImage(animatedGIF) animatedImageWithAnimatedGIFData:] in UIImage+animatedGIF.o
  "_CGImageSourceCreateWithURL", referenced from:
      +[UIImage(animatedGIF) animatedImageWithAnimatedGIFURL:] in UIImage+animatedGIF.o
  "_CGImageSourceGetCount", referenced from:
      _animatedImageWithAnimatedGIFImageSource in UIImage+animatedGIF.o
  "_kCGImagePropertyGIFDelayTime", referenced from:
      _delayCentisecondsForImageAtIndex in UIImage+animatedGIF.o
  "_kCGImagePropertyGIFDictionary", referenced from:
      _delayCentisecondsForImageAtIndex in UIImage+animatedGIF.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Run Code Online (Sandbox Code Playgroud)

我在这里做了所有的指示:http: …

testing xcode unit-testing target

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

Xcode 5如何进入存储库窗口?

在之前的XCode版本(4)中,我能够点击Xcode,它将拥有Source Control - > Repositories

现在,他们已将Source Control作为新的下拉菜单移动,但它没有存储库部分,我可以检查我的SVN并查看所有其他项目.

有没有办法打开存储库窗口?

xcode repository xcode5

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

初始化指针数据结构的空间复杂性

我有一个问题.

在理论计算机科学方面,当我们分析算法时,如果算法初始化一个新的数据结构,那么我们认为数据结构是空间复杂性的一部分.

现在我对这部分不太确定.

假设我有一个数组,int我想通过使用int指针映射来映射它们.如

std::map<int*,int*> mymap;
for (int i = 1; i < arraySize; i++) {
   mymap[&arr[i-1]]=&arr[i];
}
Run Code Online (Sandbox Code Playgroud)

如果这个算法没有使用指针,那么我们可以清楚地说它正在初始化一个大小为n的映射,因此空间复杂度是O(n),但是对于这种情况,我们使用指针的地方,空间复杂度会是多少这个算法?

c++ algorithm pointers space-complexity

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

查找 Informix 数据库服务器

我有一台服务器,我知道上面Informix安装了一个,但我不知道是谁安装的。有封闭源客户端连接到该服务器,但除了用户名和密码之外,我无法获得任何相关信息。我不知道如何连接它,我不知道它的端口号和服务器名称是什么。我已经下载SQuirreLJDBC Informix驱动程序。

如何在不知道端口和服务器名称的情况下连接到 JDBC Informix 服务器?

informix

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

如何在Eclipse中为搜索首选项添加关键字

我通过使用这个例子添加了一个偏好:http: //git.eclipse.org/c/platform/eclipse.platform.ui.git/plain/examples/org.eclipse.ui.examples.readmetool/Eclipse%20UI%20Examples %20Readme%20Tool /组织/蚀/ UI /示例/ readmetool /

有关实际参考,请参阅此页面:http: //git.eclipse.org/c/platform/eclipse.platform.ui.git/plain/examples/org.eclipse.ui.examples.readmetool/Eclipse%20UI%20Examples %20Readme%20Tool/org/eclipse/ui/examples/readmetool/ReadmePreferencePage.java)

我只添加了一个复选框来测试它,当我搜索首选项中的复选框中的任何单词时,我看不到我的视图即将出现,但如果我输入当前Eclipse有的东西,那么它出现(即我输入背景,我可以看到)在常规选项卡住并且是粗体).

我想我不知何故需要添加搜索关键字来指向当前页面(或其他东西).但我找不到如何添加,或导致此问题的原因.

那么如何在" 首选项"窗口中为我创建的首选项执行搜索?

java eclipse eclipse-plugin preference

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

Micro C OS II中的时间延迟

我一直在寻找,我正在使用Micro C/OS II实时操作系统.除了编写嵌套循环之外,我找不到创建延迟的方法.有什么办法可以造成延迟吗?

c embedded real-time real-time-systems

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

UIScrollView无法正常还原

我有一个Scrollview,它的属性在viewDidAppear中设置.现在,当我第一次到Scrollview时,没有任何问题.但是我有分配给UINavigationController的按钮.因此当我按下其中一个UINavigationController打开时,当我关闭导航控制器时,ScrollView无法正常恢复.它基本上将屏幕中心对齐为先前按下的按钮位置.因此,如果我尝试向上滚动它不会.

我试过在我的viewDidAppear中使用它:

scrollView.center = CGPointMake(scrollView.contentOffset.x, scrollView.contentOffset.y); 
Run Code Online (Sandbox Code Playgroud)

哪个不太奏效.我怎么解决这个问题?我使用的是iOS6.1

uiscrollview viewdidappear ios

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