w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
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

How can I bind data from nested List<> objects to nested ListView controls?
You can bind the datasource of your inner list view to a property of the items bound to your outer listview. However, to do that the inner listview as to be in the itemtemplate of the outer listview. See the code below and note the DataSource='<%# Eval("Labels_color") %>' attribute for the inner list view. <asp:ListView ID="ListView_Orp_Results" runat="server" ItemPlaceholderID="itemPlaceholder"> <LayoutTemplate> <div id="outer_result_container"> <div id="itemPlaceholder" /> </div> </LayoutTemplate> <ItemTemplate> <div id="result_photo">...</div> <div id="result_category">...</div> <div id="result_detector">...</div> <div id="inner_result_container" runat="server"

Categories : Asp Net

nested json with jQuery: create List of nested item
Your problem is that institut is an array containing a single object, so you can reference that single object using institut[0]. This will work: $.each(data.fakultaeten, function (key, value) { var mother = "<li id='first'>" + value.name + "<ul>"; $.each(value.institut[0], function (key1, value1) { alert(key1); }); }); Here is a working example

Categories : Jquery

Sum a nested list of a nested list of a nested list of integers
Assuming that you are only using lists, this should do the trick: def sum_nested(l): s = 0 for item in l: if type(item) is list: s += sum_nested(item) else: s += item return s

Categories : Python

Python: Split a list into nested list at points where item matches criteria
Something like this: li = [1,2,3,4000,5,6,7,8,9000,10,11,12,1300] r = [[]] # start with a list containing an empty sub-list for i in li: if i >= 2000: # start a new sub-list when we see a big value r.append([i]) else: # append to the last sub-list of r r[-1].append(i)

Categories : Python

How should i create datacontract for a List of class which contain nested list of classes as properties
What you have in your example is fine and will automatically serialize correctly. I recommend attributing your classes with [DataContract] and your properties with [DataMember] for explicitness.

Categories : Wcf

Get list of values from a nested Python data-structure using a list comprehension?
Try following: >>> from collections import namedtuple >>> >>> class P(namedtuple('_P', 'val back')): ... def __iter__(self): ... while self: ... yield self.val, self.back ... self = self.back ... >>> q = P(val=15, back=P(val=11, back=P(val=9, back=P(val=6, back=P(val=2, back=P(val=0, back=None)))))) >>> [val for val, back in q] [15, 11, 9, 6, 2, 0]

Categories : Python

Python: compare and find matches in a list of tuples and a nested list
Create an inverse mapping of data1 first: inverse_data1 = {v['code'][0]: k for k, v in data1} Now the rest is much simpler; you can look codes against that inverse mapping and find the corresponding name in O(1) time: data3 = [[inverse_data1[d[0]]] + d[1:] for d in data2 if d[0] in inverse_data1] Demo: >>> inverse_data1 = {v['code'][0]: k for k, v in data1} >>> [[inverse_data1[d[0]]] + d[1:] for d in data2 if d[0] in inverse_data1] [['Name1', '123456', 'name1'], ['Name2', '789012', 'name2']] Generally speaking, do not loop over range(len(somelist)) when you can just loop directly over that list. You can use the enumerate() function to add an index if you need one for other purposes. Your data1 and data2 lists are not of equal length, so you cannot just use indice

Categories : Python

Removing class of nested list elements based off click on outer list element?
You need this on click of A- $(this).closest('ul').find('li.active').removeClass('active'); $(this).closest('li').addClass('active') Demo -------> http://jsfiddle.net/NrGGz/

Categories : Javascript

Filtering out items from a list using nested list comprehensions in Python
You got the order mixed up: [sentence for sentence in sentences for word in words if banned_word not in sentence] Not that that'll work as that'll list the sentence every time a banned word does show up in the sentence. Take a look at the fully expanded nested loops version: for sentence in sentences: for word in words: if banned_word not in sentence: result.append(sentence) Use the any() function to test for banned words instead: [sentence for sentence in sentences if not any(banned_word in sentence for banned_word in words)] any() loops over the generator expression only until a True value is found; it'll stop doing work the moment a banned word is found in the sentence. This is more efficient at least.

Categories : Python

python: determine if all entries of a list are within entry of a nested list
I think One Should remember that both bool([False]) == True and bool([True]) == True so when construction [any(...)]: is used Any one can tells for sure that this statement will be True

Categories : Python

How to convert a nested list into a one-dimensional list in Python?
You need to recursively loop over the list and check if an item is iterable(strings are iterable too, but skip them) or not. itertools.chain will not work for [1,[2,2,2],4] because it requires all of it's items to be iterable, but 1 and 4 (integers) are not iterable. That's why it worked for the second one because it's a list of lists. >>> from collections import Iterable def flatten(lis): for item in lis: if isinstance(item, Iterable) and not isinstance(item, basestring): for x in flatten(item): yield x else: yield item >>> lis = [1,[2,2,2],4] >>> list(flatten(lis)) [1, 2, 2, 2, 4] >>> list(flatten([[1, 2, 3], [4, 5, 6], [7, 8, 9]])) [1, 2, 3, 4, 5, 6, 7, 8, 9] Works for any

Categories : Python

Grouping a list into a nested list under a condition - Python
May be there is a prettier solution, but this works: >>> A = [1.10,1.11,1.12,1.21,1.22,1.48] >>> [A[i:i+3] for i in range(len(A) - 2)] [[1.1, 1.11, 1.12], [1.11, 1.12, 1.21], [1.12, 1.21, 1.22], [1.21, 1.22, 1.48]]

Categories : Python

Why nested list indexing gets swapped with list comprehensions?
You have your loops inverted in the first version. You are creating inner tuples looping over range(len(avail)) and outer tuples with a loop over range(len(avail[i])). Your code is the equivalent (with lists instead of tuples) of this instead: outer = [] for j in range(len(avail[i])): inner = [] for i in range(len(avail)): inner.append(False if (i,j) in neighborhood else avail[i][j]) outer.append(inner) and relied on i still being assigned as a global. You can see this too when you indent your expression based on the parenthesis: return tuple( tuple( False if (i,j) in neighborhood else avail[i][j] for i in range(len(avail)) ) for j in range(len(avail[i])) ) Reverse the loops (indented differently to communicate the grouping better

Categories : Python

Group a list of list by nested size in R
To get all nested list of length equal to 1 you can do the following: P3[lapply(P3,length) ==1] ## get all elements with size equal to 1 $`2` [1] "a" $`3` [1] "b" $`5` [1] "c" Now, We can use this to group the nested lists by their lengths. We loop(lapply) over all unique lengths, and we perform the above statement for each length : lapply(unique(unlist(lapply(P3,length))), function(x) P3[lapply(P3,length) ==x] )

Categories : R

LINQ on List with lot of nested List
LINQ expressions can have multiple nested from clauses: // nested from clauses var names = from c1 in myClass1List from c2 in c1.Class2List where c2.Name == "something" from c3 in c2.Class3List select c3.Name; For completeness, here are two variants using method syntax: var names = myClass1List .SelectMany(c1 => c1.Class2List.Where(c2 => c2.Name == "something")) .SelectMany(c2 => c2.Class3List.Select(c3 => c3.Name)); var names = myClass1List .SelectMany(c1 => c1.Class2List .Where(c2 => c2.Name == "something") .SelectMany(c2 => c2.Class3List .Select(c3 => c3.Name)));

Categories : C#

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

C# Nested List not adding a new list
I have the same placement for each list creation You do NOT have the same placement of creation, the AStore is created outside of the for loop, and the APages one is.

Categories : C#

best way to iterate list and nested list
Try using a HashTable instead of the second list. In that way, you will have a direct access to the category items, without searching for them. That makes it 2 loops, which is actually 1 over all of the items in both containers If you develop OOP, I would suggest using an object with a category and a list of items. And just creating a list of these objects instead - one loop.

Categories : List

Get to nested dictionary in list
Use a list comprehension: only_last_and_first = [d for d in L if 'firstname' in d and 'lastname' in d] Now you have a list of dictionaries that have those two keys. Demo: >>> L = [{'color':'yellow','fruit':'banana'},{'firstname':'Jack','lastname':'Black'}] >>> [d for d in L if 'firstname' in d and 'lastname' in d] [{'lastname': 'Black', 'firstname': 'Jack'}] If you only wanted the first such a dictionary, use next() and a generator expression: first = next((d for d in L if 'firstname' in d and 'lastname' in d), None) Here first will be set to either the first dictionary with the two keys, or None if there is no such dictionary. If such syntax is a little daunting, here is a version with a for loop instead: first = None for d in L: if 'firstname' in d and '

Categories : Python

Indexing a nested list
Don't bother. This is almost certainly not your bottleneck, and it's not worth the headache of managing the indexing calculations and the row length variable. Timing data: >>> timeit("a[1][2]", setup="a = [[0]*5 for _ in xrange(4)]") 0.09207810811146055 >>> timeit("a[1*5+2]", setup="a = [0]*5*4") 0.06518904043262097 >>> timeit("a[1*row_length+2]", setup="a = [0]*5*4; row_length=5") 0.11411290029380439 The flattened list won when the row length was an inlined constant, but it lost when the row length was a global variable. If you try to gain an advantage by flattening your list, you will waste a ton of time managing the indexes, and unless you do it very carefully, it may even run slower. Don't bother.

Categories : Python

How to index nested list?
I would suggest to do the following: Implement the IComparable interface to the type of which the objects in the lists are. This way you can store the comparison logic inside the type itself. Create a list of this type (just like the lists in posCheckOptions). Lets call it bigList iterarte over all lists in posCheckOptions iterate over each item in the contained list and check if the item is contained in bigList. If it is, delete it from the current inner list. If not add it to bigList

Categories : C#

get deepest nested list
Here's my solution. Your get_deepest() call was not returning anything back, so there is a logical error, and it keeps going deeper. Lst = ['o', ([], [(1, 'V'), (-1, 'C')]), ['o', ['o', (['prefers'], [(1, 'D'), (1, 'D'), (-1, 'V')]), ['o', (['the'], [(1, 'N'), (-1, 'D')]), (['beer'], [(-1, 'N')])]], ['o', (['the'], [(1, 'N'), (-1, 'D')]), (['king'], [(-1, 'N')])]]] def get_dpst(L, maxdepth): deepest_tup = (L, maxdepth) for e in L: is_list = any(isinstance(e,list) for e in L) if is_list: tup = get_dpst(e, maxdepth+1) if tup[1] > deepest_tup[1]: deepest_tup = tup return deepest_tup def get_deepest(L): tup = get_dpst(L, 0) return tup[0] def printlist(lst): print '[%s]' % ', '.join(map(str, lst)) printlist(

Categories : Python

Javascript nested list css
You need to stopPropagation() to prevent the event from bubbling up the listener tree: document.getElements('li').addEvents({ mouseover: function(e){ this.addClass('css_class'); e.stopPropagation(); }, mouseout: function(){ this.removeClass('css_class'); e.stopPropagation(); } });

Categories : Javascript

jquery get last li of each nested list
Simply use :last-child as in CSS : $('#test ul li:last-child')

Categories : Jquery

nested list css problems
Here: http://jsfiddle.net/eAJjs/ $('#question > li > a').click(function () { if (!$(this).hasClass('active')) { $('#question>li>ul').slideUp(); $(this).next().slideToggle(); $('#question>li>a').removeClass('active'); $(this).addClass('active'); } else { $('#question>li>ul').slideUp(); $('#question>li>a').removeClass('active'); } }); <ul id="question"> <li><a href="#">QUESTION goes here</a> <ul> <li><a href="#">ANSWER goes here></a> </li> </ul> </li> <li><a href="#">QUESTION 2 goes here</a> <ul> <li><a href="#">ANSWER 2 g

Categories : Javascript

Targeting ol li ol li ol li, nested list with css
Your html is bad, you need to put the ol in the <li> <ol> <li>Ordered List Style</li> <li>Here’s another, they shouldn’t be too terribly long, but might wrap a line or three <ol> <li>nested</li> <li>nested <ol> <li>nested</li> <li>nested</li> </ol> </li> </ol> </li> <li>Let’s talk about the benefits of this here product!</li> <li>More feature talk! This thing is super useful, you should totally buy it!</li> </ol>

Categories : HTML

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

QML Nested List View with separators
Haven't tried it myself, but here is how to implementation a tree view in QML. http://www.codeproject.com/Articles/632795/QML-TreeModel-and-TreeView

Categories : Qt

python nested list comprehension
>>> l = [['40', '20', '10', '30'], ['20', '20', '20', '20', '20', '30', '20'], ['30', '20', '30', '50', '10', '30', '20', '20', '20'], ['100', '100'], ['100', '100', '100', '100', '100'], ['100', '100', '100', '100']] >>> new_list = [float(x) for xs in l for x in xs] >>> new_list [40.0, 20.0, 10.0, 30.0, 20.0, 20.0, 20.0, 20.0, 20.0, 30.0, 20.0, 30.0, 20.0, 30.0, 50.0, 10.0, 30.0, 20.0, 20.0, 20.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0]

Categories : Python

How to handle nested property list
You are first retrieving a Dictionary from the plist and then writing an Array. One of the 2 is wrong. Based on that you want to maybe try something like this: NSMutableArray *fruitPlist = [[NSMutableArray alloc] initWithContentsOfFile:finalPath]; NSDictionary *newFruit; for (NSDictionary *fruit in fruitPlist) { if ([fruit objectForKey:fruitName]) newFruit = fruit; } if (!newFruit) { newFruit = [[NSDictionary alloc] init]; [fruitPlist addObject:newFruit]; } else { NSInteger index = [fruitPlist indexOfObject:newFruit]; // modify newFruit as you wish [fruitPlist replaceObjectAtIndex:index withObject:newFruit]; } [fruitPlist writeToFile:finalPath atomically:YES];

Categories : IOS

Nested List view to show other
Your not following MVC, so code always looks ugly. Learn about listeners and events I have done some modification to sprfolievuand and added back button. var sprfolievu = { standardSubmit : false, items: [{ xtype : 'toolbar', items : [{ ui : 'back', text : 'back', handler : function(){ Ext.Viewport.setActiveItem(list); } }], },{ xtype: 'fieldset', title: '', items: [{ xtype: 'container', layout: 'vbox', title: '', items: [{

Categories : Extjs

Targetting specific nested UL list with css
According to the HTML standard, the p element is implicitly closed before any "block level" element, including ul. So your markup is effectively equivalent to <h2>Capabilities</h2> <p class="about"> </p><ul> <li>Branding & Art Direction</li> <li>Interface Design</li> <li>Adobe Creative Suite</li> <li>Web Standards & Accessibility</li> </ul> <p></p> and the ul is the immediate sibling of p.about: .about + ul { ... } But wouldn't it easier just to set .about class to the ul itself?

Categories : HTML

Scala Reflection of Nested List
This snippet shows matching to pull apart the type, and the two calls to showType show what you're doing and what you intend. val cType = sym.typeSignature def showType(t: Type): Unit = { if( t.typeSymbol.fullName.toString == "scala.collection.immutable.List" ) { t match { case PolyType(typeParams, resultType) => println(s"poly $typeParams, $resultType") case TypeRef(pre, sym, args) => println(s"typeref $pre, $sym, $args") val subtype = args(0) println("Sub:"+subtype) showType(subtype.typeSymbol.typeSignature) showType(subtype) } } } showType(cType)

Categories : List

Knockout Computed sum of Nested list
An easy fix for this is to make sure you have Accounts before you try to use it in a computed. When Accounts exists this will notify your computed to recompute - var HouseholdViewModel = function(data) { this.$type = 'HouseholdViewModel'; ko.mapping.fromJS(data, mapping, this); this.T12 = ko.computed(function () { var total = 0; if (!this.Accounts) { return 0; } ko.utils.arrayForEach(this.Accounts(), function (account) { total += account.T12Revenue(); }); return total; }, this); }; Add the if statement in there to return nothing (or whatever you want) incase that this.Accounts does not exist.

Categories : Jquery

Using 'nested' types in a list in Scala
The method signature for workWithList looks wrong - where does the ListItemType type come from? Should this be def workWithList(list: ObservableList[ListItem[_]]) { ...? If so, then the problem you will run up against in the match cases is that due to type erasure, the JVM can't tell the difference at runtime between the type signatures of the cases. This can be worked around by, for example, turning the Type1, Type2 and ListItem into case classes (or manually generating unapply methods for them), then deconstructing the item in the match cases, like so: case class Type1(anInt: Int) case class Type2(aString: String) case class ListItem[T](internalValue:T) object Worker { val list1 = FXCollections.observableArrayList[ListItem[Type1]]() val list2 = FXCollections.observableArrayLis

Categories : Scala

Show/Hide nested list with css
I assume you want to show the nested list onclick? I'd suggest to go with jQuery (JavasScript) and do something like this $('ul.outerlist>li').on(`click`, function(){ $(this).find('ul.innerlist').toggle(); }); EDIT: that's the easiest way I can imagine. Anything else depends on what exactly you are trying to achieve.

Categories : HTML

Nested List as a Parameter in WCF web service
When you add your Service Reference and the dialog pops up you can click the Advanced... button in the lower left and change the Collection type drop-down from System.Array to System.Collection.GenericList this will then change the proxy that is created and use List<...> instead of [...] when collections are used. In addition, if you have already added your Service Reference you can right-click on the Service Reference within the Solution tree and click Configure Service Reference... from the context-menu. This will show the same "Advanced" dialog mentioned above.

Categories : C#

nested list filtering in python?
This should be equivalent, filteredList = [b for b in bookmarkList if tag in b[1]] I also think you meant to break after your append otherwise you'd get multiples.

Categories : Python

Add List to Nested Repeater Control
I was trying to do the wrong thing here! I needed to have a RowDataBound command. This updates the nested gridview in the parent gridview. protected void AddPrincipleStaff_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow)// Bind nested grid view with parent grid view { var psid = DataBinder.Eval(e.Row.DataItem, "PrincipleStaffID"); int intpsid = 0; intpsid = Int32.Parse(psid.ToString()); using (var context = new FactoryTheaterModelFirstContainer()) { var query = (from c in context.PrincipleStaffs from p in c.Employees where c.PrincipleStaffID == intpsid

Categories : C#



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