any

Generic struct with a reference to the same type but with any concrete type

百般思念 提交于 2019-12-11 04:29:00
问题 My intention is to create a struct that holds a reference to another one of a similar type, but with different generics to be used as a chain of linked objects. The problem is that writing this using the _ placeholder is not allowed: the type placeholder `_` is not allowed within types on item signatures E0121 I cannot simply give my struct another type parameter since the referenced object may reference another object too, and so on. This would lead to a very large number of type parameters,

How to write C function accepting (one) argument of any type

落花浮王杯 提交于 2019-12-10 03:42:01
问题 I am implementing simple library for lists in C, and I have a problem with writing find function. I would like my function to accept any type of argument to find, both: find(my_list, 3) and find(my_list, my_int_var_to_find) . I already have information what is type of list's elements . For now I've found couple of ways dealing with this: different function with suffix for different types: int findi(void* list, int i) , int findd(void* list, double d) - but I don't like this approach, it seems

How to achieve python's any() with a custom predicate?

邮差的信 提交于 2019-12-09 08:32:05
问题 >>> l = list(range(10)) >>> l [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>> if filter(lambda x: x > 10, l): ... print "foo" ... else: # the list will be empty, so bar will be printed ... print "bar" ... bar I'd like to use any() for this instead, but any() only takes one argument: the iterable. Is there a better way? 回答1: Use a generator expression as that one argument: any(x > 10 for x in l) Here the predicate is in the expression side of the generator expression, but you can use any expression there,

“Any” boolean function in jquery

只谈情不闲聊 提交于 2019-12-08 15:05:32
问题 Is there any easy way to check if any elements in a jquery selector fulfill a condition? For instance, to check if any textboxes in a form are empty (kind of pseudo, not real jquery): $('input.tb').any(val().length == 0); Note: I know it could be done with a helper method, just curious if it was possible in one statement. 回答1: jQuery has a lot of pseudo selectors built in: http://api.jquery.com/category/selectors/jquery-selector-extensions/ You can also build your own with the filter()

How to pass a path as argument to shell script and copy a file from the path

廉价感情. 提交于 2019-12-08 13:40:54
问题 I've written bash script to open a file passed as argument and write it into another file. But my script will work properly only if the file is in the current directory. Now i need to open and write the file that is not in the current directory also. If compile is the name of my script, then ./compile next/123/file.txt should open the file.txt in the passed path. How can I do it? #!/bin/sh #FIRST SCRIPT clear echo "-----STARTING COMPILATION-----" #echo $1 name=$1 # Copy the filename to name

Java KeyListener - How to detect if any key is pressed?

青春壹個敷衍的年華 提交于 2019-12-08 08:16:00
问题 I've added a KeyListener to a TextArea and wish to check if any key is pressed down. I have the following but it's too clumsy to check for all the letters and numbers: public void keyPressed(KeyEvent e) { if(e.getKeyCode() == KeyEvent.VK_A || e.getKeyCode() == KeyEvent.VK_B || e.getKeyCode() == KeyEvent.VK_C ||e.getKeyCode() == KeyEvent.VK_D etc...){ } } 回答1: You wouldn't need any if statements. The keyPressed method is fired whenever a key is pressed, so you're automatically thrown into the

Find a value of a dictionary in dataframe column and modify it

坚强是说给别人听的谎言 提交于 2019-12-08 04:13:36
问题 I dealing with DataFrames and Dictionaries now, and i have a problem, I have a Dictionary " Fruits " {BN:'Banana', LM:'Lemon', AP:'Apple' ..... etc} And a DataFrame- " Stock ": Fruit Price 0 Sweet Mango 1 1 Green Apple 2 2 Few blue Banana 0 3 Black Banana 5 I wand to do the next thing: replace all the values from Stock['Fruit'] with the Fruits.values() this way: if the value from Fruits appears in the Stock['Fruit'] row it will be replaced this way: Few blue Banana ---> Banana Black Banana --

Compare Boolean Row values across multiple Columns in Pandas using & / np.where() / np.any()

让人想犯罪 __ 提交于 2019-12-07 20:20:55
问题 I have a dataframe that looks like: a A a B a C a D a E a F p A p B p C p D p E p F 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 2 0 1 0 0 0 0 0 0 1 0 0 0 3 0 0 1 0 0 1 0 0 0 0 0 0 4 0 0 0 1 0 1 0 0 0 0 0 0 5 0 0 0 0 1 0 0 0 0 0 0 0 6 0 0 0 0 0 0 1 0 0 0 0 0 df = pd.DataFrame({'p A':[0,0,0,0,0,0,1],'p B':[0,0,0,0,0,0,0],'p C':[0,0,1,0,0,0,0],'p D':[0,0,0,0,0,0,0],'p E':[0,0,0,0,0,0,0],'p F':[0,0,0,0,0,0,0],'a A':[0,1,0,0,0,0,0],'a B':[0,0,1,0,0,0,0],'a C':[0,0,0,1,0,0,0],'a D':[0,0,0,0

How to use numpy.all() or numpy.any()?

梦想与她 提交于 2019-12-07 20:04:57
问题 I am trying to search in a 2D numpy array for a specific value, the get_above method returns a list of coordinates above the character 'initial char' def get_above(current, wordsearch): list_of_current_coords = get_coords_current(current, wordsearch) #print(list_of_current_coords) length = len(list_of_current_coords) first_coords = [] second_coords = [] for x in range(length): second = list_of_current_coords[x][1] new_first = list_of_current_coords[x][0] - 1 first_coords.append(new_first)

SQL - Find the grade of students who only like students in the same grade

て烟熏妆下的殇ゞ 提交于 2019-12-07 07:30:53
问题 I am doind a free Stanford online course (which is pretty cool, you should check that out) and I've been racking my brains for the lest 2 days and can't find an answer to the following problem. Please help. Question 4 Find names and grades of students who only have friends in the same grade. Return the result sorted by grade, then by name within each grade. When I finally thought that I had the answer my query returned all the values from the table Friend. This is the best I could come up