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

Visual C++: checked list box doesn't clear
Selected items are not the same thing as checked items. Selected means you have a (usually blue) highlight on the item and checked means the checkbox is ticked. To clear all the checkmarks, you have to use the SetItemChecked method rather than ClearSelected which is actually inherited from ListBox and has nothing to do with check boxes: for (int i = 0; i < checkedListBox1->Items->Count; ++i) { checkedListBox1->SetItemChecked(i, false); }

Categories : Visual C++

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

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

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

Create nested list view from JSON
it's very simple: just put list value inside the list with id taskList: <script type="text/javascript" charset="utf-8"> $.getJSON("fakultaeten.js",function(data) { var list = $('#taskList'); $.each(data.fakultaeten, function(key,value) { var mother = "<li>"+value.name+"<ul>"; $.each(value.institut, function(key1,value1) { var son="<li>"+value1+"</li>"; mother+=son; } ); mother+="</ul></li>"; list.append(mother); } ); list.listview("refresh"); return false; } ); </script>

Categories : HTML

To do list example doesn't work for me
first check whether myEditText.setOnKeyListener is getting fired when you pressing Enter. If yes then add these properties in your edittext xml ndroid:singleLine="true" android:lines="1" Hope it will work.

Categories : Java

C List Pop doesn't work on first run
I just used your code with my implementation of GetOperations() and Print(). The code works fine. //Structure to represent node typedef struct node { char *data; struct node * next; } Node; //Pop top value from Linked list Node * Pop (Node ** head) { if (*head == NULL) { printf("Error popping! List is empty. "); return NULL; } Node * temp = *head; *head = (*head)->next; return temp; } //Create node and save data Node *createNode(int i) { char *n=malloc(sizeof(4*sizeof(char))); n[0]='O'; n[1]='p'; n[2]=(char)(((int)'0')+i); n[3]=''; Node *temp=(Node*)malloc(sizeof(struct node)); temp->data=n; temp->next=NULL; return temp; } //Create a list with data Node* GetOperations() { int i; Node *head=NULL,*curre

Categories : C

use file content to create a nested list in python
Use str.split and a list comprehension: with open('filename') as f: table_data = [ line.split() for line in f] If you want the numbers to be converted to integers then write an additional function that processes each item on a give line: def func(x): try: return int(x) except ValueError: return x >>> with open('abc1') as f: ... table_data = [[ func(x) for x in line.split()] for line in f] ... >>> table_data [[12, 'john', 'E', 44, 'L'], [13, 'adam', 'D', 78, 'L'], [14, 'tue', 'E', 98, 'L']]

Categories : Python

Create arbitrarily nested list structure in Haskell
In Haskell all elements of a list need to have the same type. So you can't have a list where one element is an integer and another element is a list. Therefore [1, [2, 3]] would cause a type error in Haskell. So if you want to represent arbitrarily nested structures like this, you'll need to define your own type for that. That could look like this: data Tree a = Leaf a | Branch [Tree a] A value of that type could then look like this: Branch [ Leaf 0, Leaf 0, Branch [ Leaf 1, Leaf 1, Branch [ Leaf 2, Branch [ Leaf 3], Leaf 2], Leaf 1]]

Categories : Haskell

ThreadLocal and list doesn't work
You invoke run() method instead of start(). run() runs in the same thread it is invoked, while start() invokes run() in a new, separate thread. In effect, all your "threads" are executed in the same thread.

Categories : Java

Background of Div with list doesn't work
Add overflow:auto; to #topbar. Check: http://jsfiddle.net/NGyWu/12/ Alternatively you can use clearfix

Categories : HTML

How to create nested list from PHP array for dropdown select field?
It does not work because you are not setting the "parent" attribute right. Even if the name is "Test 2.1", using this algorithm, you have to set the parent index. If you change your array to this, it'll work: $rows = array( array ('id' => 1, 'name' => 'Test 1', 'parent' => 0), array ('id' => 2, 'name' => 'Test 1.1', 'parent' => 1), array ('id' => 3, 'name' => 'Test 1.2', 'parent' => 1), array ('id' => 4, 'name' => 'Test 1.2.1', 'parent' => 3), array ('id' => 5, 'name' => 'Test 1.2.2', 'parent' => 3), array ('id' => 6, 'name' => 'Test 1.2.2.1', 'parent' => 5), array ('id' => 7, 'name' => 'Test 2', 'parent' => 0), array ('id' => 8, 'name' => 'Test 2.1', 'parent' => 7), array ('id' =&g

Categories : PHP

the delete Item of a list doesn't work
you use _id as column but you have not it. your create query is @Override public void onCreate(SQLiteDatabase dc) { dc.execSQL("CREATE TABLE " + TABLE_CLIENT + " (id INTEGER PRIMARY KEY, nom_complet TEXT NOT NULL, adresse_client TEXT NOT NULL, numero_telephone TEXT NOT NULL)"); } or you change the the query inside onCreate (id for _id), or use id in the delete query public void onListItemClick(final ListView parent, View v, final int position, final long id) { selectionc.setText("Vous êtes sur : " + stg1[position]); AlertDialog.Builder builder = new AlertDialog.Builder(this) .setTitle("Delete Item") .setMessage("are you sure to delete?") .setPositiveButton("Yes", new DialogInterface.OnClickListener() { @Override

Categories : Android

wrap_content doesn't work on list view
I want to add little comment, but my reputation isn't enough to. And my opinion could be wrong. Karakuri's answer on CommonsWare's links is exactly right answer i think. and this google guy said why we shouldn't use wrap_content on ListView. http://www.youtube.com/watch?v=wDBM6wVEO70&t=40m40s And about your comment, my opinion is that, ScrollView's height is probably wrap_content with scroll vertically. If then, ScrollView's height will be adapter's height or ImageView's height. Bcuz, ScrollView doesn't care how many ListItem should be displayed. It only check how many view or groupview is exist inside of itself. And I also recommend you don't use ListView inside of ScrollView (or opposite). Because, both view have to check touch-move event to scroll their view. If you mix it, andr

Categories : Android

create a list from another list and remove elements from copied list
Yes your understanding is correct. List newList = new ArrayList(collection); will do a shallow copy. You can modify the newList without affecting the original collection, but they will each reference the same elements so if you modify an element in one list, the other list's element will also get the change. This is called a Shallow Copy. Here's a visual representation of what I've described: The things at the bottom are the objects in your array.

Categories : Java

Appending to create a list instead of creating a list inside a list
Use extend: for item in items: forename = re.findall(pattern2, item) surname = re.findall(pattern3, item) mainlist.extend(surname) myList.extend(L) adds the individual elements of L onto myList. It's similar to: for element in L: myList.append(element)

Categories : Python

Create larger list from an existing list using a list comprehension or map()
How about: >>> atom_indices = [0, 4, 5, 8] >>> coords = [3*a+k for a in atom_indices for k in range(3)] >>> coords [0, 1, 2, 12, 13, 14, 15, 16, 17, 24, 25, 26] We can nest loops in list comprehensions in the same order we'd write the loops, i.e. this is basically coords = [] for a in atom_indices: for k in range(3): coords.append(3*a+k) Don't be afraid of for loops, though, if they're clearer in the situation. For reasons I've never fully understood, some people feel like they're being more clever when they write code horizontally instead of vertically, even though it makes it harder to debug.

Categories : Python

Create List only if Session doesn't exist
Try defining the variable products outside the if, if session variable is null you create a new list, otherwise you retrieve the one stored in the session variable: public ActionResult Add(int productId) { List<int> products; if (Session["ShoppingList"] == null) { products = new List<int>(); } else { products = (List<int>) Session["ShoppingList"]; } products.Add(productId); Session["ShoppingList"] = products; return View("Index"); }

Categories : C#

Is it possible plot using ordered dictionary or list, OrderedDict doesn't work
Something like this? I assume you are trying to sort the dictionary by value pylab.plot(*zip(*sorted(dc.items(), key=lambda x:x[1]))) To switch the axes use this pylab.plot(*reversed(zip(*sorted(dc.items(), key=lambda x:x[1])))) To sort by key, just leave the key=... out

Categories : Python

i18next and JQuery doesn't work in form's drop down list
I found a workaround. I noticed that when I sent my form and reset it, the dropdown list was correclty displayed. So after initializing i18n, I used this: document.getElementById("form").reset(); The form is now displayed correctly.

Categories : Jquery

why reversed() list iteration with step doesn't work properly?
Reversed takes a list and reverses it. The slicing notation iterates over the list and returns a new one. When you call reversed on the slice (with or without stepping) of a list, the slice is created first, and then reversed. For example, newL = reversed(L[0:len(L):2]) is the same as: M = L[0:len(L):2] newL = reversed(M) Thus, when you say reversed(L[0:len(L)-1:2]), reversed is called on a list containing every other element in L, starting with the first, and excluding the last. As a side note, L[::2] is the same as L[0:len(L):2], and L[:-1:2] is the same as L[0:len(L)-1:2]. Also, L[::-1] is L in reverse order. This notation is very powerful. If you want a checkio([5, 8, 13, 27, 14]) to return [14, 13, 5, 27, 8], then here are a few ways to do it: >>> L = [5, 8, 13, 27, 1

Categories : List

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

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

I have designed a sorting algorithm for a char linked list in c++ but it doesn't work
Replace while (point != NULL) { while (current != NULL) { By while (point != NULL) { current = point->next; while (current != NULL) {

Categories : C++

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

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

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

How does "knife ec2 server create"'s expansion of --run-list work?
This is a feature of bash. [] is a wildcard expander. You should can escape the brackets using "".

Categories : Amazon

Clear Cache App: Why it doesn't work?
here's my suggestion of how to fix your errors. i could make it even better, but it should work just fine. cache.setOnPreferenceClickListener(new OnPreferenceClickListener() { clearCache(getApplicationContext()); } and here are the functions , fixed: public static void clearCache(final Context context) { final File cache=context.getCacheDir(); final File appDir=new File(cache.getParent()); if(appDir.exists()) { // you might be able to change this whole code block to just "deleteDir(appDir)" final String[] children=appDir.list(); for(final String childFilePath : children) if(!childFilePath.equals("lib")) { deleteDir(new File(appDir,childFilePath)); Log.i("TAG","**************** File /data/data/APP_PACKAGE/"+childFilePath+" DE

Categories : Java

d3.js using brush.clear() doesn't work for me
brush.clear() only resets the extent. You need to call brush again to redraw the brush. The documentation for brush.extent has some details about this.

Categories : Javascript

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

Bootstrap, clear both doesn't work properly
It's because you use: .row-fluid [class*="span"]:first-child { margin-left: 0; } and .row-fluid [class*="span"] { margin-left: 2.127659574468085%; } You can remove left margin from div with clear: <div style="clear: both; margin-left: 0px;" class="span3 tlo2 my_height_box">aabc</div> jsfiddle Or replace left margin from all this divs with margin-right

Categories : HTML

Why does Python operator.itemgetter work given a comma separated list of numbers as indices, but not when the same list is packaged in a variable?
This isn't about itemgetter, but about function calling syntax. These are different things: operator.itemgetter(1, 3, 5) operator.itemgetter((1, 3, 5)) The first one gets you item #1, item #3, and item #5. The second one gets you item #(1, 3, 5). (Which may make sense for a dictionary, but not for a list.) The second one is what you get when you use itemgetter(columns). So, how do you get the first? operator.itemgetter(*columns) That's it. See Unpacking Argument Lists in the tutorial for more information.

Categories : Python

android:clearTaskOnLaunch doesn't work How to clear the backstack when comes to foreground?
Add tag android:clearTaskOnLaunch="true" to root (main) activity tag in manifest. Then user will always return to this activity. To jump to Login from any other activity, use: public static void logoff(Context c){ Intent logoff = new Intent(c,LoginActivity.class); logoff.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK); c.startActivity(logoff); }

Categories : Android



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