w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Python list operation (append multiple lists)
You can use a list of lists: table = [[] for i in range(5)] with open('test.txt', 'r') as handle: for line in handle: for index, value in enumerate(line.strip().split('|')): table[index].append(value) So instead of having list1, list2, etc., you just access the cells by table[0][0], table[2][1], etc.

Categories : Python

MVC 4 binding nested list of lists result
http://haacked.com/archive/2008/10/23/model-binding-to-a-list.aspx It's an old article, but it still applies. I had this exact problem, but basically due to the model binding system you need to use an explicit for loop instead of a foreach loop, and reference your elements by their index. @using (Html.BeginForm("Edit", "Person", FormMethod.Post, new { id = "validate-form", @class = "block-content form" })) { Html.AntiForgeryToken() Html.HiddenFor(x => x.PersonID) for (int i = 0; i<Model.Tabs.Count; i++) { Html.EditorFor(x => Model.Tabs[i]) } <input class="close-toolbox button" type="submit" value="Save"> }

Categories : Asp Net Mvc

List operation for nested list
Use a nested list comprehension: otherlist = [[(L[0], t) for t in L[1]] for L in lst] so for each element L in lst, we create a new list with tuples containing (L[0], elements of L[1]). Demo: >>> lst = [(1, [('a1', 'b1', 'c1'), ("a1'", "b1'", "c1'"), ('a1"', 'b1"', 'c1"')]), (2, [('a3', 'b3', 'c3'), ("a3'", "b3'", "c3'"), ('a3"', 'b3"', 'c3"')]), (3, [('a3', 'b3', 'c3'), ("a3'", "b3'", "c3'"), ('a3"', 'b3"', 'c3"')])] >>> [[(L[0], t) for t in L[1]] for L in lst] [[(1, ('a1', 'b1', 'c1')), (1, ("a1'", "b1'", "c1'")), (1, ('a1"', 'b1"', 'c1"'))], [(2, ('a3', 'b3', 'c3')), (2, ("a3'", "b3'", "c3'")), (2, ('a3"', 'b3"', 'c3"'))], [(3, ('a3', 'b3', 'c3')), (3, ("a3'", "b3'", "c3'")), (3, ('a3"', 'b3"', 'c3"'))]]

Categories : Python

List comprehension for turning a lists of lists of strings into a list of lists of ints and float
Another option is using map >>> bins = [['1', '2', '3.5'], ['4', '5', '6.0']] >>> map(lambda x: [int(x[0]), int(x[1]), float(x[2])], bins) [[1, 2, 3.5], [4, 5, 6.0]]

Categories : Python

Plus Arithmetic Operation
Wrap both plus and plus1 in parseInt() so you add instead of concatenate. var plus = parseInt( document.getElementById('plus').value ), plus1 = parseInt( document.getElementById('plus1').value );

Categories : Javascript

How to find elements that are common to all lists in a nested list?
You can use reduce and set.intersection: >>> reduce(set.intersection, map(set, nested_list)) set([2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0]) Use itertools.imap for memory efficient solution. Timing Comparisons: >>> lis = [[1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,10.0,11.0,12.0,13.0,14.0,15.0], [2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,10.0,11.0,12.0,13.0,14.0], [1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,10.0,11.0,12.0,13.0,14.0], [2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,10.0,11.0,12.0,13.0,14.0,15.0]] >>> %timeit set.intersection(*map(set, lis)) 100000 loops, best of 3: 12.5 us per loop >>> %timeit set.intersection(*(set(e) for e in lis)) 10000 loops, best of 3: 14.4 us per loop >>> %timeit reduce(

Categories : Python

gdb python: How to do arithmetic operation on a gdb.value?
You are subtracting two values of pointer type. This means that the result, as in C, is divided by the size of the object. Instead, ensure that "offset" has an integral type, not a pointer type. In the last example you are trying to subtract strings. You can't do that. Move the calls to "hex" from the computations to the prints and it will work.

Categories : Python

Can we do some arithmetic operation within double quotes?
You have posted that Your required output is // 5 + 11 = 16 . So You may try the below code. $x = 5; $y = 11; echo "$x + $y=".($x+$y); I think this will give Your required output.

Categories : PHP

'List of lists' to 'list' without losing empty lists from the original list of lists
Are you starting with the strings 'a', 'b', etc.? If so then you can use ''.join to convert ['a'] into 'a' and [] into ''. [''.join(l) for l in list_of_lists]

Categories : Python

stored procedure arithmetic operation with casting
please try SELECT CAST(row1 AS DOUBLE PRECISION)/row2) FROM myTable WHERE row3 = "value" INTO myVar; Let me know if it work. Regards Ashutosh Arya

Categories : SQL

Make an AFNetworking operation complete before next code line after [operation start] and how to handle nested operations
This is not an AFNetworking related question, rather a general Objective-C or asynchronous question. You may try to reload the table view whenever the images of one model have been loaded: - (void)getAllModels{ NSURLRequest *request = ...; AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) { for(NSDictionary *model in JSON){ Model *model = [Model alloc] initWithId:...; [model getPhotosWithCompletionBlock: ^(NSArray *results){ dispatch_async(dispatch_get_main_queue(), ^{ model.photos = results; [self.tableView reloadData]; }); }failureBlock:^(NSError *error) { N

Categories : Misc

NUnit System.OverflowException: Arithmetic operation resulted in an overflow
Well It did appear to be an incorrect range value on one rogue test. The perils of copy and pasting. That said, I still don't understand why it affected every other test in the assembly. Even the correct tests failed when run individually, that is until I corrected the error. Thanks for your hep.

Categories : C#

Printing items within a list within a list, etc. (Printing nested lists)
The function has no argument called C therefore you cannot pass it a keyword argument called C. Either use directory=... instead or pass it the object as a normal argument. C = ... tree_traverse(C)

Categories : Python

How to insert nested lists (or nested block elements) into RichTextBlock?
Ok Ill start with silverlight. There was a TreeView Control in silverlight that would have exactly solved your problem. Link to tree view example But since we already know that winRt is a subset of API's these controls have been removed for metro app. More over microsofts design policy regarding the Type Of scenario you are mentioning has changed to : Semantic Zoom For Metro Apps So i advise if your app requirement is like that Either go with the richtextbox or use Grids with Rows and columns Which ever suits your coding best. One more way is to use third party library for tree structure . Syncfusion tree control Syncfusion has a tree control you can try out in the Demo. Even there are more third party tool but none are free not even he above one. Please Let me know if any more co

Categories : HTML

How should I implement a list in of lists in Java? Or is there a better way than a list of lists?
The best idea would be to use Point Point point = new Point(1,4); List<Point> points = new ArrayList<Point>(); Another way is to use list of lists. Not recommended. Not object oriented List<List<Integer>> Alternatively you can create your version of Point class. For example an object which will have one axis inside class AxisX{ private List<Integer> } And put it inside another object class Coordinates{ private List<AxisX> }

Categories : Java

Python creating a lists of lists of floats from a single list of strings
The problem is that your inner lists are references to one single list and not individual lists. >>> objectListDataFloats = [[0] * len(objectListData[0].split(', '))] * len(objectListData) >>> objectListDataFloats [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]] >>> id(objectListDataFloats[0]) == id(objectListDataFloats[1]) True After you fix that, you need to iterate from the starting index of 0, since the lists in Python start their index from 0. for count in range(len(objectListData)): for ii in range(len(objectListData[count].split(', '))): objectListDataFloats[count][ii] = float(objectListData[count].split(', ')[ii]) >>> objectListDataFloats [[1.0, 2.0, 3.0, 4.0], [5.0, 6.0, 7.0, 8.0], [9.0, 0.0

Categories : Python

Python and remove duplicates in list of lists regardless of order within lists
Frozensets are perfect for cases like this, when you need to nest sets: >>> A = [[1,2,3], [2,3,4], [3,4,5], [3,2,4]] >>> smaller_A = {frozenset(x) for x in A} >>> smaller_A {frozenset({1, 2, 3}), frozenset({2, 3, 4}), frozenset({3, 4, 5})} To convert back to lists, you can do this: >>> [list(x) for x in smaller_A] [[1, 2, 3], [2, 3, 4], [3, 4, 5]] This won't conserve the order of your lists or the elements inside them. (Although it didn't make a difference here.) If you do need to preserve order, you can iterate over A while keeping track of frozensets seen so far: >>> A = [[1,2,3], [2,3,4], [3,4,5], [3,2,4]] >>> seen = set() >>> smaller_A = [] >>> for x in A: ... if frozenset(x) not in seen: ... s

Categories : Python

Python: a fast way to remove subsets of lists in a list of lists
def simplify(l): i = 0 while i < len(l): s = set(map(abs,l[i])) for x in xrange(len(l)): if x == i: continue if s <= set(map(abs,l[x])): l.pop(i) i -= 1 break i += 1 This removes any list that is a subset of another list in the 2d list. (The set <= operator is implemented to mean ⊆).

Categories : Python

Python: operation being unexpectedly propagated along parent lists
You need to make either a shallow copy or a deep copy (if you need to recursively copy inner objects) using c = b[:] or copy.deepcopy(b). Doing c = b, just creates a reference pointed to the same object as by b, so, if b changes or c changes, both the variables reflect those changes. >>> a = range(11) >>> b = [] >>> for i in a: b.append(i+1) >>> print b [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11] >>> c = b[:] >>> c.insert(-1, 10.5) >>> print c [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10.5, 11] >>> c.remove(11) >>> print c [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10.5] >>> print b [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]

Categories : Python

In Python, how do I sum multiple lists-of-lists on certain sub-list's fields?
This seems to give what you want using more pythonic list comprehensions. >>> [[e[0][0], sum(int(r[1]) for r in e), sum(int(r[2]) for r in e)] for e in zip(a, b, c)] [['jane', 8, 405], ['bob', 4, 47], ['joe', 8, 200]] If you want it to work with out of order names, you could do something like this >>> from itertools import groupby >>> [[name] + reduce( lambda a, b: [int(c) + int(d) for (c,d) in zip(a, b)], [r[1:] for r in records]) for name, records in groupby( sorted(r for l in [a, b, c] for r in l), lambda r: r[0]) ] [['bob', 4, 47], ['jane', 8, 405], ['joe', 8, 200]] Don't judge me. I don't really write code like that.

Categories : Python

Creating a new nested list element that is a combination of two existing nested list elements (in R)
Here are your for loops using replicate (Note that the expression value for each replicate is the same expression you have in the assignment portion of your for loop) ## This is your inner for-loop, using replicate inds <- seq(begin, end, 10) datas <- replicate(length(inds), list('mean'=vector(mode='list',length=12),'sd'=vector(mode='list',length=12)) , simplify=FALSE) names(datas) <- inds # This is your outer loop tardis2 <- replicate(length(dataLayers), list('longName'='timeLord','units'='theDr','data'=datas) , simplify=FALSE) names(tardis2) <- dataLayers # Compare Results identical(tardis2, tardis) # [1] TRUE However, I'm not sure if lists are relaly the best structure for this. Have you considered data.frames?

Categories : R

Select a subset of lists from list of lists
You can use something like: ll[which(sapply(ll, `[[`, 1) == .4)] But you might run into floating point problems.... Here's an MRE: A list with 4 items. ll <- list(list(.4, 1), list(.1, 2), list(.3, 3), list(.4, 4)) # [[1]] # [[1]][[1]] # [1] 0.4 # # [[1]][[2]] # [1] 1 # # # [[2]] # [[2]][[1]] # [1] 0.1 # # [[2]][[2]] # [1] 2 # # # [[3]] # [[3]][[1]] # [1] 0.3 # # [[3]][[2]] # [1] 3 # # # [[4]] # [[4]][[1]] # [1] 0.4 # # [[4]][[2]] # [1] 4 Apply the proposed solution: ll[which(sapply(ll, `[[`, 1) == .4)] # [[1]] # [[1]][[1]] # [1] 0.4 # # [[1]][[2]] # [1] 1 # # # [[2]] # [[2]][[1]] # [1] 0.4 # # [[2]][[2]] # [1] 4 Adding multiple conditions is pretty similar: ll[which(sapply(ll, `[[`, 1) == .4 & sapply(ll, `[[`, 2) == 1)] # [[1]] # [[1]][[1]] # [1] 0.4 #

Categories : R

Python: given a list of lists, create a list ordered by the number of occurrences in inner list
You can use collections.Counter to keep a counter for each element inside each sublist. Something like this, >>> from collections import Counter >>> lst = [['a','b','c'], ['a'], ['a','b']] >>> counts = Counter() >>> for sublst in lst: ... for ele in sublst: ... counts[ele] += 1 ... >>> [ele for ele, _ in counts.most_common()] ['a', 'b', 'c']

Categories : Python

In a responsive site design, how do i put a list below other list that contains a sub-list without overlap the main lists
Pretty simple : remove the fixed height of your li.menulinks, add a "header" (green rounded rectangle with 35px height) div as first child of the li and...you're set ! Look at this fiddle : http://jsfiddle.net/32pga/ <div class="sitemap"> <div class="row-fluid"> <ul> <li class="menulinks"> <div class="menulinks-header"></div> <ul> <li class="submenulinks"> <div>Test 1</div> </li> <li class="submenulinks"> <div>Test 2</div> </li> <li class="submenulinks"> <div>Test

Categories : HTML

Knockout.js nested lists
I was able to get the formatting I wanted with the following html markup: <div id="tourneys_in_progress"> <h2>Open Tournaments</h2> <div id="tourneys"> <ul data-bind="template: { name: 'tourneyTemplate', foreach: tourneys.CurrentTournaments }"></ul> <script id="tourneyTemplate" type="text/html"> <li class="tourneys"> <div class="tourney"> <div data-bind="text: 'TournamentType: ' + TournamentTypeString"></div> <div data-bind="text: 'Number of Rounds: ' + Rounds" ></div> <div data-bind="text: 'Boards: ' + Boards" ></div> <div data-bind="text: 'Players per Board: ' + PlayersPerBoard"></di

Categories : Knockout Js

Nested lists and percentages
I'm interested by what you are trying to achieve. It's not something I've ever had to do, but you have brought up an interesting point. I also think you may have mis-understood the way some of the inheritance works. Just because you put relative positioning on an element doesn't change the way the sub elements get their widths. Percentage widths always get their widths based on their parent element, whether it's relative positioned or whatever. In most cases the parent fills the space of it's parent, etc. There is definitely a certain amount of 'zen' that needs to be grasped when it comes to CSS and yes continuing in web-development could cause the loss of hair! Buy a stress ball and you should be ok :) As for heights that's a different story as it's buggy as hell and generally doesn't pic

Categories : HTML

Nested Lists in PHP and MySQL
query SELECT a.item, b.item, c.item FROM TOP_LEVEL a JOIN SECOND_LEVEL b ON b.level = a.level JOIN THIRD_LEVEL c ON c.level = b.level ORDER BY a.item, b.item, c.item code <?php $q = "SELECT a.item, b.item, c.item FROM TOP_LEVEL a JOIN SECOND_LEVEL b ON b.level = a.level JOIN THIRD_LEVEL c ON c.level = b.level ORDER BY a.item, b.item, c.item "; ...... your database stuff...... ...... resulting array should be two-dimensional `$items` ...... $c = 0; echo "<ul> "; while ($c < count($items)) { for ($j = 0; $j < count($items[$c][0]); $j++) { echo "<li>$items[$c][0] "; echo "<ul> "; for ($k = 0; $k < count($items[$c][1]); $k++) { echo "<li>$items[$c][1] "; echo "<ul> "; for ($i = 0; $i &

Categories : PHP

Indexing nested lists in R
The lists would be extracted with [[ and the matrices (not lists) with [,] indexing, but you need to give the functions something to work with. (At the moment you are not.) So if you wantend the 4h matrix and the i,j values were 10 and 3 this would deliver that value: myNestedList[[4]][10,3] The evaluation proceeds left to right. Wrapped in a function and assuming from context that you only wanted the i-th column (which is a bit confusing since i usually refers to rows): pull.ith.col.from.nth.mat <- function(lis, n, i) lis[[n]][ , i]

Categories : R

Nested Lists in MVC 4 page
From within any view, you can call an action from any controller. As an example, the Razor ActionLink helper allows you to pass a controller name along with the method name from that controller: @Html.ActionLink("Link text, "Action Name", "Controller Name") And a form that posts to a different controller than the one that rendered the view: @Html.BeginForm("Action Name", "Controller Name", FormMethod.Post, new { enctype = "multipart/form-data" })) { // Form fields } Whether or not you want to do this depends on the overall design of your application. It may be simpler to create a "RefundVoucher" ViewModel that encapsulates the data that you need from your Refund and Voucher Models and create a controller and strongly-typed views for that.

Categories : Asp Net Mvc

Replace values from list into numbers then perform arithmetic calculation
You can use match and sapply: df1$x <- sapply(df1$x, function(x) df2$value[match(x, df2$x)]) df1$x # [[1]] # [1] "5.2" "1.8" "2.7" "3.8" "5.0" # # [[2]] # [1] "3.8" "5.0" "3.2" "4.5" "2.4" "3.9" # # [[3]] # [1] "3.8" "5.0" "3.2" "4.5" "2.4" # # [[4]] # [1] "3.2" "2.4" Per comment: To average each row, you can use sapply again: sapply(df1$x, mean) Or in one step: sapply(df1$x, function(x) mean(df2$value[match(x, df2$x)]))

Categories : R

nested for loops in python with lists
Use the zip function, like this: list1=['a','b'] list2=['y','z'] for i, j in zip(list1, list2): print(i, j) Output: ('a', 'y') ('b', 'z')

Categories : Python

A program to mutate Nested Lists
You can use recursion: def capitalize_list(t): N = [] for i in range(len(t)): if type(t[i]) == str: N.append(t[i].capitalize()) if type(t[i]) == list: N.append(capitalize_list(t[i])) return N Output: ['A', 'B', ['C', 'D'], ['E'], 'F']

Categories : Python

Lists with multiple 'nested' items
You have to access the list elements with [[ instead of [: for(i in cats){ l1[[i]][1]<-"hello" };l1 for(i in cats){ l1[[i]][2]<-"goodbye" };l1 > l1$red[1] [1] "hello" > l1$red[2]

Categories : R

How to perform AND operation in Mongodb for a query on nested array of objects
Instead of individual field values you can also use whole objects in find queries. Try: db.collection.find( { users: { "name":"foo", "status":"a" } }); This should return all documents where the users array includes an object (or is an object) which looks as described. But note that this doesn't work when the object has additional fields.

Categories : Mongodb

Nested select lists and loading information
Its because use change the html so event cannot work you need to add event listener every time like this function bindEvent(){ $('.standing_leagues').on('change',function(){ var standing_id = $(this).children(":selected").attr("id"); alert(standing_id); }); } See Demo Call that function on every time you change the html of .leagues class

Categories : Jquery

JSON serializer with nested object lists
Turns out you don't need to use a serializer at all. You just return type object. public object NavigationItems() { using (TTConnection connection = new TTConnection("ClientDb")) { if (MySession.Current.MyClub == null) return USER_ERROR; MiddleTier.WebNavigation.WebNavigationGenerator gen = MySession.Current.NavGenerator; List<NavigationElement> list = gen.GetNavigation(); return list; } }

Categories : C#

MVC4 Razor syntax one-to-many nested lists
You are going to want to use linq's groupby to do that. @{ foreach (var parent in Model.GroupBy(m => m.ParentTable.DisplayName)) { <div> @parent.Key @foreach( var itm in parent ) { <ul> <li> <span> @itm.City </span> <span> @itm.State</span> </li> </ul> } </div> } }

Categories : Linq

Nested Json Lists formatting incorrectly
The issue is not really in removing the u from the start of those strings. The easiest way to do this is to import the json module and call json.dumps(checklist.json()['list']). It will do the right thing for you. The strings the json module returns are unicode objects (and are represented in the repr) as unicode literals. To "remove" them you need to handle the unicode strings better and this is the easiest way that will result in the least hair pulling and most forward compatibility with python 3.

Categories : Python

C++ Data Structure for Nested Number Lists
A Trie is likely to be the most efficient structure for something like this. You can find an overview on what Trie's are here. Essentially Trie's store values where there are liable to be many overlaps early in the values (like strings or sequences of numbers), by only storing each value at each position once. The diagram you drew almost exactly depicts a Trie.

Categories : C++

Adding two lists and getting XML output in nested form
You should create an object which contains an application and a list of environments, like ApplicationWithEnvironments. List<ApplicationWithEnvironments > AppWithEnvlist = new ArrayList<ApplicationWithEnvironments >(); for(ApplicationDTO d: allApplication) { ApplicationWithEnvironments appWithEnv = new ApplicationWithEnvironments(); Application a = new Application(); a.set... appWithEnv.setApplication(a); for(EnvironmentDTO en: d.getEnvironment()) { Environment e = new Environment(); e.set... appWithEnv.addEnvironment(e); } AppWithEnvList.add(appWithEnv); } ArrayList<MyModel> obj= new ArrayList<MyModel>(); MyModel mm = new MyModel(

Categories : Java



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.