any

Python: any() unexpected performance

允我心安 提交于 2019-12-21 17:19:25
问题 I am comparing the performance of the any() built-in function with the actual implementation the docs suggest: I am looking for an element greater than 0 in the following list: lst = [0 for _ in range(1000000)] + [1] This is the supposedly equivalent function: def gt_0(lst): for elm in lst: if elm > 0: return True return False And these are the results of the performance tests: >> %timeit any(elm > 0 for elm in lst) >> 10 loops, best of 3: 35.9 ms per loop >> %timeit gt_0(lst) >> 100 loops,

Press anykey to continue in Linux C++

雨燕双飞 提交于 2019-12-19 10:08:55
问题 I am not sure if being in linux makes any different, but i have found online that this: cout << "Press Enter to Continue..."; cin.ignore(numeric_limits<streamsize>::max(),'\n'); Should be sufficient, with #include<limits> in the header of course. However, it does not seem to work in my program. It compiles, it runs, but it does not wait. Basically, i have a menu, which lead to a method call to display a list of people on the screen. I wish to pause that list before the system goes back to the

Linq To Entities - Any VS First VS Exists

你。 提交于 2019-12-19 05:12:28
问题 I am using Entity Framework and I need to check if a product with name = "xyz" exists ... I think I can use Any(), Exists() or First(). Which one is the best option for this kind of situation? Which one has the best performance? Thank You, Miguel 回答1: Any translates into "Exists" at the database level. First translates into Select Top 1 ... Between these, Exists will out perform First because the actual object doesn't need to be fetched, only a Boolean result value. At least you didn't ask

Linq To Entities - Any VS First VS Exists

只愿长相守 提交于 2019-12-19 05:12:02
问题 I am using Entity Framework and I need to check if a product with name = "xyz" exists ... I think I can use Any(), Exists() or First(). Which one is the best option for this kind of situation? Which one has the best performance? Thank You, Miguel 回答1: Any translates into "Exists" at the database level. First translates into Select Top 1 ... Between these, Exists will out perform First because the actual object doesn't need to be fetched, only a Boolean result value. At least you didn't ask

SQLAlchemy filter query “column LIKE ANY (array)”

删除回忆录丶 提交于 2019-12-18 14:57:06
问题 Hi SQLAlchemy experts out there, here's a tricky one for you: I'm trying to write a query that resolves into something like: SELECT * FROM MyTable where my_column LIKE ANY (array['a%', 'b%']) using SQLAlchemy: foo = ['a%', 'b%'] # this works, but is dirty and silly DBSession().query(MyTable).filter("my_column LIKE ANY (array[" + ", ".join(["'" + f + "'" for f in token.tree_filters]) + "])") # something like this should work (according to documentation), but doesn't (throws "AttributeError:

postgreSQL - in vs any

て烟熏妆下的殇ゞ 提交于 2019-12-17 22:45:37
问题 I have tried both 1) smthng = any (select id from exmplTable) 2) smthng in (select id from exmplTable) and I am getting the same results for my data. Is there any difference for the two expresions ? 回答1: No, in these variants are same: You can see - the execution plans are same too: postgres=# explain select * from foo1 where id in (select id from foo2); ┌──────────────────────────────────────────────────────────────────┐ │ QUERY PLAN │ ╞═══════════════════════════════════════════════════════

How to assign a value to [any]

吃可爱长大的小学妹 提交于 2019-12-13 22:30:30
问题 When I set c to a var a: [Any] var c: Array<PostCategory> error shown: cannot convert value of type 'Array' to expected argument type [Any] how to solve the problem? 回答1: The error message is a bit misleading but try initializing the array before assigning it: var c: Array<PostCategory> = [] ...or... var c = Array<PostCategory>() 回答2: I bet your PostCategory is a struct . Apparently struct arrays aren't convertible to an Any array. This is weird because all types conforms to the Any protocol.

Python - Returning the value if there is an “exact” match?

陌路散爱 提交于 2019-12-13 01:45:51
问题 lst = ['a', 'b', 'c', 'aa', 'bb', 'cc'] def findexact(lst): i=0 key = ['a','g','t'] while i < len(lst): if any(item in lst[i] for item in key): print lst[i] i+=1 findexact(lst) in the above code, the result comes out to be: 'a' 'aa' I would like the result to be: 'a' What is the right way to use any() to get the right result? 回答1: To match your expected output, you cannot use set.intersection as sets are unordered so if you get a as the first item it is totally by chance , you should make key

Type parameter vs Any in Scala

為{幸葍}努か 提交于 2019-12-12 02:13:34
问题 I have a class RBase, and a RInt class that inherits from it. The Base has three interface functions. As the subclasses that inherit can use different type of values, the function parameter is typed as Any. As a result, I need to use asInstanceOf to implement the subclasses. This is an example. abstract class RBase(val name:String) { def encode(value:Any) : Array[Byte] def decode(byteArray: Array[Byte]) : Any def check(value:Any) : Boolean } class RInt extends RBase("int") { override def

any_cast std::any pointer to specific pointer type

≯℡__Kan透↙ 提交于 2019-12-11 06:06:16
问题 I would like std::map<string, any> *var1 to point to the same memory address/value as std::any *var2 because I know that var2 is pointing to a map<string, any> . The following seems to work: std::map<string, any> *var1 = any_cast<std::map<string, any>>(var2); Is it ok? The problem is that it does not signal bad cast even if var2 is actually not an std::map<string, any>* but something else, but if it is it still works. Am I doing it right? std::map<string, any> *mapptr; std::any realmap = std: