• <p>jedi里if,else的用法本身也有三种，作为instruction，作为后置条件，作为表达式，同一个token在不同环境下承担不同职责是不好学，不好找，不好记的 ...
• What is the best approach in python: multiple OR or IN in if statement? Considering performance and best pratices.if cond == '1' or cond == '2' or cond == '3' or cond == '4' (etc...) :ORif cond in ['1...
What is the best approach in python: multiple OR or IN in if statement? Considering performance and best pratices.if cond == '1' or cond == '2' or cond == '3' or cond == '4' (etc...) :ORif cond in ['1','2','3','4']:Thank you.解决方案The best approach is to use a set:if cond in {'1','2','3','4'}:as membership testing in a set is O(1) (constant cost).The other two approaches are equal in complexity; merely a difference in constant costs. Both the in test on a list and the or chain short-circuit; terminate as soon as a match is found. One uses a sequence of byte-code jumps (jump to the end if True), the other uses a C-loop and an early exit if the value matches. In the worst-case scenario, where cond does not match an element in the sequence either approach has to check all elements before it can return False. Of the two, I'd pick the in test any day because it is far more readable.
展开全文
• c# Dictionary的TryGetValue的用法

万次阅读 2016-03-28 10:10:35
如果遇到要取不确定数据时候不能这么写： ...if (theDictionary.ContainsKey(id)) { result = theDictionary[id]; //What ever you gonna do next... } 得是用TryGetValue，以减少一次不必要查找： myObjec

如果遇到要取不确定的数据的时候不能这么写：

myObject result = null;
if (theDictionary.ContainsKey(id))
{
result = theDictionary[id];
//What ever you gonna do next...
}

得用TryGetValue，以减少一次不必要的查找：

myObject result = null;
if (theDictionary.TryGetValue(id, out result))
{
//What ever you gonna do next...
}


展开全文
• Python中的break和continue的用法

千次阅读 2014-04-20 19:36:06
# ***************************************************************************** # This is a program to illustrate the useage of break in Python....# What if we want to jump out of the loop completely—ne

一、continue的用法（结束当前的循序，进行下一个数的循环）

# *****************************************************************************
# This is a program to illustrate the useage of continue in Python.
# If you want to stop executing the current iteration of the loop and skip ahead to the next
# continue statement is what you need.
# ****************************************************************************
for i in range (1,6):
print
print 'i=',i,
print 'Hello,how',
if i==3:
continue
print 'are you today?'

运行结果如下：
>>> ================================ RESTART ======================
>>>
i= 1 Hello,how are you today?
i= 2 Hello,how are you today?
i= 3 Hello,how
i= 4 Hello,how are you today?
i= 5 Hello,how are you today?
>>>

二、break的用法（结束总的循环）

# *****************************************************************************
# This is a program to illustrate the useage of break in Python.
# What if we want to jump out of the loop completely—never finish counting, or give up
# waiting for the end condition? break statement does that.
# ****************************************************************************
for i in range (1,6):
print
print 'i=',i,
print 'Hello,what is ',
if i==3:
break
print 'the weather today?'
运行结果如下：
>>> ================================ RESTART ========================
>>>
i= 1 Hello,what is  the weather today?
i= 2 Hello,what is  the weather today?
i= 3 Hello,what is
>>>


展开全文
• 一、用于引导名词性从句引导词有以下几类： 连接代词： what, which, who, whom, ...whether,if （均表示“是否”表明从句内容不确定性）；as if ,as though （均表示“好像”，“似乎”） 二、what, whic...
一、用于引导名词性从句的引导词有以下几类：

连接代词： what, which, who, whom, whose
连接副词： when, where, why, how
连接连词： that （宾语从句或表语从句中"that"有时可以省略）；whether,if （均表示“是否”表明从句内容的不确定性）；as if ,as though （均表示“好像”，“似乎”）

二、what, which在从句中作主语、宾语、表语或定语；who在从句中作主语、表语；whom在从句中作宾语；whose在从句中作定语；when, where, why, how在从句中分别作时间状语、地点状语、原因状语、方式状语。例如
1.Choose which you like best.
选你最喜欢的。

2.Who has taken away my bag is unknown.
谁拿走了我的包还不知道。

3.Have you decided whom you are to nominate as your candidate?
你们是否已经决定提名谁做候选人了?

4.He asked when Mr. Gilbert would be allowed to go home.
他问什么时候可以允许吉尔伯特先生回家。

5.Where we can look up his address is still a problem.
我们在哪儿可以查到他的地址还是个难题。

6.Why he did that wasn’t quite clear.
他为什么做那件事还不十分清楚。

7.How they will solve the serious problem has not been decided.
他们将怎样解决这个严重问题还没有决定。

三、what作连接代词引导的名词性从句既可以表示一个问“什么……？”的问题， 也可以表示相当于“名词/代词＋关系代词引导的定语从句”结构的意思， 这种特殊用法在语法上被称作“关系代词型的what”，例如：
1. He is not what (=the person that) he was a few years ago.
他不是几年前的他了。

2. This is what (=the place that) they call Salt Lake City.
这就是他们称作盐湖城的地方。

3. What (=the place that) is now the North Sahara Desert was once a civilized world.
现在的北部撒哈拉沙漠曾是一个文明世界。

4.Our income is now double what (=the income that) it was ten years ago.
我们现在的收入是十年前的两倍。

5.The color of the flower is different from what (=the color that) it was in the morning.
花朵(现在的)颜色与它早上的颜色不同。

6.How did the cheats explain the fact that the Emperor didn't feel the new clothes in him?
皇帝觉得身上并没有穿上新衣，对这个问题骗子是怎样解释的?

7.I owe it to you that I am still alive.
幸亏你，我现在还活着。

8.She made a request that the doctor(should)be sent for at once.
她请求立即请医生来。

9.You must see to it that the children don't catch cold.(=You must see to it,and It is that the children don't catch cold.）
你要当心，别让孩子们着凉了。

10.She told me that she would accept my invitation.
她告诉我，她接受我的邀请。



展开全文
• <p>What $Z->get('user')</code> and$je</code> are supposed to be is a MySQLi result object. This gives weird effects like print_r not functioning and it just doesn't look right. <p>I want to check...
• c# Dictionary.TryGetValue()的用法

万次阅读 2018-10-29 17:26:02
if (theDictionary.ContainsKey(id)) {  result = theDictionary[id];  //What ever you gonna do next... } 当在字典中不能确定是否存在该键时需要使用TryGetValue，以减少一次不必要查找，...
• <p>What is the difference between the two examples? Which of these 2 above is correct? Is one preferred over the other in certain situations? <p>I am writing a program which creates multiple <code>...
• If yes, what gives me that guarantee that the UI(ajax framework) I use today will continue to work with no change over the next 2-3 browser versions? <p>EDIT: Please don't assume that I have ...
• If it means I always have to do some extra coding to keep all stored times in correct UTC+0, I will take that for granted. Based on ISO-8601 and the timezone aberrations and daytime-savings I will ...
• regret 用法

千次阅读 2018-03-27 10:00:22
① regret+ n./pron.If you don’t do it now, you’ll only regret it.如果现在不做，以后一定会后悔。The airline regrets any inconvenience.航空公司对所造成任何不便表示歉意。② regret + that/wh- 从句I ...
• if (msg.what == 02234) { Bundle bundle = msg.getData(); String timeout = bundle.getString("e1"); System.out.println(timeout); Toast.makeText(MainActivity.mactivity, "timeout="+timeout, Toast....
• I can have access to validate() method but the problem is, its not in the current class and even if its being inherited from the base or parent class, I shouldn't be able to access it through \$this ...
• 上代码// what is the fucking shit.cpp : 定义控制台应用程序入口点。 // #include "stdafx.h" #include #define VERSION_XZM 1 #define VERSION_HAERBIN _T("哈尔滨\n") #define VERSION_TIANJIN _T("天津
• ROracle各种命令用法

千次阅读 2014-11-03 17:45:14
dbCommit-methods 说明：在Oracle里事务提交和回滚   使用方法： dbCommit(conn, ...) dbRollback(conn, ...)   举例： drv con dbReadTable(con,"EMP") ...if(dbGetInfo(rs, what ="rowsAffect
• needed only if' the focus is set somewhere else in the Grid.tmpRow = Grid1.RowtmpCol = Grid1.Col' Set Row and Col back to what they were before Text1_LostFocus:Grid1.Row = gRowGrid1.Col = gColGrid1.Te...
• <p>This is what the regular help flag outputs: <pre><code>Cancel the order specified by the order id by submitting a cancel order. Optionally, an account ID may be supplied as well for extra measure....
• If I have thousands of images and even more tags, this data structure can grow very large if image URL strings are copied by value for each tag. This is where I want to leverage pointers. <p>I can ...
• <h3>I am new to go (coming from python and ruby) and want to know what is the idiomatic way of calling functions on a struct? <p>Mostly I want to know if I should use the dot operator to call ...
• 一般我们使用判断语句写法都是如下所示： # else子句 ...if name.endswith('Gumby'): print('hello,Mr.Gumby') else: print('Hello,stranger') what is your name?andy Hello,stranger 有一个与...
• It is important to mention that I use PHP so I cannot overload methods and I can pass any datatype to an argument because of PHP's type juggling ability. To make easier to understand what I want, ...
• <p>What is the best way to refactor repeated code base like below? I looked at a few different ... Is it better if I use deference operator and pointer for the receiver with ApiResource? </div>
• <p>I see a lot of answers on Stackoverflow and what the operator accomplishes, but nobody ever says WHY they would use it over just typing out <code>12345</code> so like I said, why use them and what ...
• <p>So while trying to port the code to Go while learning the language at the same time, this is what I started with to test the basic idea: <pre><code>func main() { tree := make(map[string]interface...
• <p>I'm using an open source package that leverage the <code>runtime.Gosched()</code> to wait for a resource to ... And what's the use case of Gosched, if it's not suitable for this situation. </div>
• import csvwith open('in.csv')as f:head = next(f)# decide delimiter by what is in headerdelim = "," if "," == head[0] else " "# need to filter empty stringshead = filter(None, head.rstrip().split(del.....
• <p>Now what I want is to use the <strong>postLists</strong> post structure in my page for three different categories and here I am stuck because when I pass variable to component like this - <code>{ %...
• <p>I started kidding around with Go and am a little irritated by the <code>new</code> function.... And if that is correct, in what situation should <code>new</code> be used? </div>
• throw new Error("My God, What version of IE are you using? IE5&+ is requiered."); } } else throw new Error("Cannot create DOM Document!"); } function ValidationFramework() {} ...
• <p>Is a PHP session varriable the session ID ? if not , then what is the exact use of a session variable when we already have a unique session ID ??? Can someone please explain ? an example would ...