combinations

Find maximum int value from list which contain both str and int python

旧街凉风 提交于 2019-12-17 20:43:03
问题 Looking to find max from the combine list as follows: ['filename1', 1696, 'filename2', 5809,....] I have tried following: max(['filename1', 1696, 'filename2', 5809,....]) that return me TypeError: '>' not supported between instances of 'int' and 'str' . Any suggestion would help. What I want is to find the max integer value from the list above mentioned. 回答1: Use list comprehension with isinstance to extract the int and then use max . Ex: f = ['filename1', 1696, 'filename2', 5809] print(max(

Words combinations without repetition

…衆ロ難τιáo~ 提交于 2019-12-17 20:19:22
问题 I have 10 words. How can I get all possible combinations of 5 words (n=10, k=5) . The order does not matter . For example: "A", "B", "C", if k=2 (n=3 in this case) , it would like AB, BC and AC. Maybe you know some usefull code or example. P.S. Sorry if I'm not right enough cause I don't know English very good. 回答1: What you are trying to do is get all the permutations of a collection. Unique permutations of list permutations of k objects from a set of n algorithm Here is the code snippet:

Combinations by group in R

巧了我就是萌 提交于 2019-12-17 20:10:39
问题 I have a question about combinations by group. My mini-sample looks like this: sample <- data.frame( group=c("a","a","a","a","b","b","b"), number=c(1,2,3,2,4,5,3) ) If I apply the function of combn to the data frame,it gives me following result, which is all the combinations of the values under the 'number' column regardless of which group the value belongs to: [,1] [,2] [1,] 1 2 [2,] 1 3 [3,] 1 2 [4,] 1 4 [5,] 1 5 [6,] 1 3 [7,] 2 3 [8,] 2 2 [9,] 2 4 [10,] 2 5 [11,] 2 3 [12,] 3 2 [13,] 3 4

Java: Generator of true's & false's combinations by giving the number N;

回眸只為那壹抹淺笑 提交于 2019-12-17 18:59:21
问题 I tied to simplify the task as much as possible, so I could apply it to my algorithm. And here is the challenge for mathematicians and programmers: I need to create a method where I pass parameter int n: public void optionality_generator(int n){ //some kind of loops, or recursions...to make it workable System.out.println("current combination: ..."); } The output should show all possible combinations of true's and false's. Here is examples where N=1; N=2; N=3; N=4; N=5 where x=false and 0=true

Creating a list of all possible unique combinations from an array (using VBA)

此生再无相见时 提交于 2019-12-17 14:57:19
问题 Background: I'm pulling all of the field names from a database into an array - I've got this part done without a problem, so I already have an array containing all the fields (allfields()) and I have a count of how many fields there are (numfields). I am now trying to compile all of the unique combinations that can be made from those various field names. For example, if my three fields are NAME, DESCR, DATE, I would want to return the following: NAME, DESCR, DATE NAME, DESCR NAME, DATE DESCR,

How can I obtain all the possible combination of a subset?

坚强是说给别人听的谎言 提交于 2019-12-17 14:55:02
问题 Consider this List<string> List<string> data = new List<string>(); data.Add("Text1"); data.Add("Text2"); data.Add("Text3"); data.Add("Text4"); The problem I had was: how can I get every combination of a subset of the list? Kinda like this: #Subset Dimension 4 Text1;Text2;Text3;Text4 #Subset Dimension 3 Text1;Text2;Text3; Text1;Text2;Text4; Text1;Text3;Text4; Text2;Text3;Text4; #Subset Dimension 2 Text1;Text2; Text1;Text3; Text1;Text4; Text2;Text3; Text2;Text4; #Subset Dimension 1 Text1; Text2

Getting all combinations which sum up to 100 using R

一个人想着一个人 提交于 2019-12-17 14:54:18
问题 I need to get all combinations for which the sum equal 100 using 8 variables that could take any value from 0 to 100 by incremental step of 10. (i.e. 0, 10, 20 ... 100) The following script does just that but is very inefficient as it creates a huge dataset and I was wondering if someone had a better way of doing this. x <- expand.grid("ON" = seq (0,100,10), "3M" = seq(0,100,10), "6M" = seq(0,100,10), "1Y" = seq(0,100,10), "2Y" = seq(0,100,10), "5Y" = seq(0,100,10), "10Y" = seq(0,100,10),

All possible combinations of columns in dataframe -pandas/python

泪湿孤枕 提交于 2019-12-17 14:52:41
问题 I'm trying to take one dataframe and create another, with all possible combinations of the columns and the difference between the corresponding values, i.e on 11-apr column AB should be (B-A)= 0 etc. e.g, starting with Dt A B C D 11-apr 1 1 1 1 10-apr 2 3 1 2 how do I get a new frame that looks like this: I have come across the below post, but have not been able to transpose this to work for columns. Aggregate all dataframe row pair combinations using pandas 回答1: You can use: from itertools

Compute rank of a combination?

浪子不回头ぞ 提交于 2019-12-17 10:47:12
问题 I want to pre-compute some values for each combination in a set of combinations. For example, when choosing 3 numbers from 0 to 12, I'll compute some value for each one: >>> for n in choose(range(13), 3): print n, foo(n) (0, 1, 2) 78 (0, 1, 3) 4 (0, 1, 4) 64 (0, 1, 5) 33 (0, 1, 6) 20 (0, 1, 7) 64 (0, 1, 8) 13 (0, 1, 9) 24 (0, 1, 10) 85 (0, 1, 11) 13 etc... I want to store these values in an array so that given the combination, I can compute its and get the value. For example: >>> a = [78, 4,

PHP take all combinations

不羁的心 提交于 2019-12-17 09:51:15
问题 I saw this algorithm that will take numbers or words and find all possible combinations And I'm using it, but it does NOT return all "real" combinations. PHP: <?php require_once 'Math/Combinatorics.php'; $words = array('cat', 'dog', 'fish'); $combinatorics = new Math_Combinatorics; foreach($combinatorics->permutations($words, 2) as $p) { echo join(' ', $p), "\n"; } ?> And it returns: cat dog dog cat cat fish fish cat dog fish fish dog But these are not all real combinations, all real