[Solved] Concatenating int and list in c# [closed]

If I understand you correctly, you want to add random number to every candidate key number. If that is the case try this. var candidatekey = new List<int> { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; var randomnumber=42; //we are using LINQ on list candidatekey=candidatekey.Select(c => c+randomnumber).ToList(); 1 solved Concatenating int and … Read more

[Solved] indexing for python list of lists

Here is a simple function to do what you want: def get_length_or_value(l, *i): item = l for index in i: item = item[index] return len(item) if isinstance(item, list) else item This function first finds the element at the given indices (if any), and then returns the appropriate value based off wether the element is a … Read more

[Solved] Get the first word and second word using list comprehensions [closed]

You can use zip to process two lists in parallel. Zip will stop iteration at the shorter of the two lists. mashemup = [x.split()[0] + ‘ ‘ + y.split()[1] for x, y in zip(meeps, peeps)] print(mashempup) [‘Foghorn Cleese’, ‘Elmer Palin’, ‘Road Gilliam’, ‘Bugs Jones’, ‘Daffy Chapman’, ‘Tasmanian Idle’] Or if you need a list of … Read more

[Solved] How can I loop through a data structure? [closed]

I believe it should just be a couple of small typos. First, your second line looks like it should be indented, and where you have links[“property”], it looks like you would want link[“property”]. for link in links: payload[f’Links[{link[“property”]}][url]’] = link[‘url’] The reason it is giving you that error is that you are trying to get … Read more

[Solved] Create a list for each item in another list

I wouldn’t recommend this course of action. You will probably get all kind of replies telling how you can do this using setattr and friends, but in practice dynamically-created variable names are almost invariably (see what I did there?) a bad idea. Suppose you already have a variable called X_list and then you process a … Read more

[Solved] How do I access list inside an object [closed]

OP, this code makes me want to weep for little children, but the reason you’re getting errors is because you’re placing 4 separate variables in MessageBox.Show() call and not tying them together. Update Based on your comment, when I try to type oH_N1_N1.ListH_N1_N2, there is no N201_Name01 and N201_Name02 That’s because oH_N1_N1.ListH_N1_N2 is a List<H_N1_N2> … Read more

[Solved] List permutation existance

A variation on Save’s solution: var fixedSet = new HashSet<int>(){A,B,C}; bool result = PossibleSolutions.Any(x => fixedSet.SetEquals( new[] { x.CapacitorALocation,x.CapacitorBLocation,x.CapacitorCLocation })); 3 solved List permutation existance

[Solved] Sorting a list based on associated scores [closed]

I would approach this as follows: from collections import defaultdict # using defaultdict makes the sums easier correlations = defaultdict(int) # default to int (i.e. 0) for i1, i2, correl in strScoresDict: # loop through data correlations[i1] += correl # add score for first item correlations[i2] += correl # and second item output = sorted(correlations, … Read more

[Solved] Define a function count_down() that consumes a number a produces a string counting down to 1 [closed]

Not a code-writing service nor a tutorial. But for its simplicity’s sake, a possible solution could look like def count_down(n): return ‘, ‘.join(str(i) for i in range(n, 0, -1)) # return ‘, ‘.join(map(str, range(n, 0, -1))) >>> count_down(5) ‘5, 4, 3, 2, 1’ join, str, range are very fundamental functions/methods you should read up on … Read more