w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Learning Python lists, tuples
There's no need to join the two elements of the list together into a single string. You want to iterate over the elements of the list: for user in users: file = '/Users/' + user + '/sync.log' print("created: %s" % time.ctime(os.path.getctime(file))) print("last modified: %s" % time.ctime(os.path.getmtime(file)))

Categories : Python

Android multiple lists using @id/android:list
I figured it out. I didn't ever post the relevant code, or I'm sure you guys would have spotted it for me. I copied a non working adapter from a working piece of code which returns false if the viewType is 0. And since my second list only has one type, everything was disabled. Thank you all for your efforts. I apologize that I didn't give you the correct code.

Categories : Java

Optimize regex matching m:n lists (multiple words lists agains multiple lists)
You can try to change : bmw.*red.*1999 to bmw(?>[^r]++|Br|r(?!ed))++red(?>[^1]++|B1|1(?!999))++1999 and the same for all keywords. The goal with this change is to fail faster as possible. Note that the transformation can be automated with 2 successive search/replace (it is always the same) search: (w+) replace: $1 search: .*(?=\b(w)(w+)\b) replace: (?>[^$1]++|B$1|$1(?!$2))++ example with the second keyword toyota.*black.*1999 first replace: toyota.*black.*1999 second replace: toyota(?>[^b]++|Bb|b(?!lack))++black(?>[^1]++|B1|1(?!999))++1999 Then you store the compiled expression in your database.

Categories : Regex

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

how to sort 2 lists at once in android
Rather than storing the contactNumber and contactName of people in separate Lists. You can create a class Person which encapsulates contactName and contactNumber . Populate the List<Person> and then sort it . Or use can use a Map<String,String> where key will be contactNumber and value the contactName.

Categories : Android

Android, Best way to store lists of data
There are basically a few options: Use a SQlite Database and optionally hide it behind a ContentProvider Let your Classes implement Serializable and save things with ObjectStream to some file to persist them Implement some custom String serialization (eg. JSONObject / JSONArray / XML) to save your objects in SharedPreferences Pros/Cons: Quite an overhead but faster than the others when you got more than a couple of objects. Easy to implement, not that fast, OK for a couple objects Easy to implement, even slower, OK for a few objects, upgrading your data structure can break thinks. be prepared. So in the end, it depends on your use case. Further readings: https://developer.android.com/guide/topics/data/data-storage.html

Categories : Android

find difference between lists and append difference to lists, but for 40 different lists - python
Sounds like you could use sets: >>> {1, 2, 3, 4, 5} & {2, 3, 4, 5, 6, 7} & {3, 4, 5} {3, 4, 5} & is the intersection operator for sets. Get a set of a list (this will remove duplicate elements with set(mylist). Edit: In the light of your comments, it seems what you need is some sort of union (the union operator being |), not an intersection. Here is a function that does what you wanted in your comment for 2 lists of lists: def function(first, second): first_set = {tuple(i) for i in first} second_set = {tuple(i) for i in second} return (first_set | {(i[0], 0) for i in second_set}, second_set | {(i[0], 0) for i in first_set}) >>> a = [(1,60),(3,90)] >>> b = [(2,30),(4,50)] >>> x, y = function(a, b) >>> pri

Categories : Python

Flickering of dropdown lists in Android (appverse)
(Answering my own post) After reading tons and tons of logs, I've found the reason of this problem. This happens because the application goes to background when the software keyboard appears and this forces the dropdown -contained in the Webview- to close. Similar issue here: WebView hides soft keyboard during loadUrl(), which means a keyboard cannot stay open while calling javascript Since the problem has been detected only in certain versions of Android, I'll workaround it by using the dropdown UI of jQueryMobile. Ugly, slow, fragile... but it works.

Categories : Javascript

Making it efficient: Android Parcelables, Interfaces and Lists
I would go for writeParcelableArray, if you know the size won't change and *List if the size changes dynamically. Pass null as the classloader to use the base/default classloader.

Categories : Android

Bind to a Dictionary of Lists of Lists of Bools with a strongly-typed MVC view by using Checkboxes
Alright, I got it. I tried using a Tuple<int, List<List<bool>>> instead of a Dictionary<int, List<List<bool>>>. That failed, apparently because the Tuple doesn't have a 0-parameter constructor. Then, I tried using a custom class that had two properties, an int and a List<List<bool>>. I got that to work after some fiddling, and once that worked I was able to reverse engineer it and get the Dictionary to work. Here's the working version (same view model and iidToData as before): ... @{ string machineID; Submission subm; tblSignatures sig; ItemSearchResult result; int kvInd = 0; var dc = new CloudDataContext(); } ... foreach( KeyValuePair<int, List<ItemSearchResult>> kv in ViewBag.iidToData ) { ... <input type="

Categories : Asp Net Mvc

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

Merging lists of lists retaining order with groovy
Consider this solution, though it is somewhat brittle (e.g. when keys do not align). Also, this modifies the 'first' list as a side-effect, which is a bit of a smell. // modifies 'first' as a side-effect def merge = { def first, def subSecond -> def subFirst = first.find { it[0] == subSecond[0] } if (subFirst) { subFirst.addAll( subSecond[1..subSecond.size()-1] ) } } // tests def first = null def results = null first = [["A",2,4,6],["B",1,3,5]] results = [] results.each { def subSecond -> merge(first,subSecond) } assert [["A",2,4,6],["B",1,3,5]] == first first = [["A",2,4,6],["B",1,3,5]] results = [ ["A",8,10,12] ] results.each { def subSecond -> merge(first,subSecond) } assert [["A",2,4,6,8,10,12],["B",1,3,5]] == first first = [["A",2,4,6],["B",1,3,5]]

Categories : List

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

Pairwise addtion of two lists mutating one of the source lists
You're probably initializing listB like this: listB = listA This just makes the two variables point to the same list object. If you mutate one, you mutate the other. Clone the list instead: listB = list(listA) listB = listA[:] # Or

Categories : List

python merging dictionary of lists of lists/tuples
Instead of returning a list of list for 'current' and 'past', I am using a dict here, as it is a more appropriate data structure for this case. In case if you still want them to return a list then you can use total['current'].items() or total['past'].items() from itertools import chain d1 = {'current': [[1369713600, 29], [1369756800, 47], [1369800000, 34]], 'curr_total': 110, 'past': [[1368417600, 2], [1368460800, 70], [1368504000, 10]], 'past_total': 82} d2 = {'current': [(1369713601, 23), (1369756800, 87), (1369800000, 7)], 'curr_total': 117, 'past': [(1368417600, 100), (1368460800, 7), (1368504000, 9)], 'past_total': 116} total = {} for k,v in chain(d1.iteritems() ,d2.iteritems()): if isinstance(v, list): for k1, v1

Categories : Python

With android Chrome, html option lists ignore my font size request
As you found out it's impossible to change the font size of the option select dialog. This is for very good usability reasons. Is there a reason why you need more options shown at once? Why is the dialog's scrolling not good enough for your needs? Also remember that if you make the options too small you may frustrate your users. You may be able to accurately select an option but other people may not. All that said you could get round these limitations by coding your own dialog, perhaps by using radio buttons. For example: <input type="radio" id="distDV30" name="distDV" value="30"><label for="distDV30">+30</label> <input type="radio" id="distDV29" name="distDV" value="29"><label for="distDV29">+29</label> You could then style that however you like. An

Categories : Android

Removing lists-within-lists from my prolog code
Assuming your Prolog implementation has an append predicate, you could do this: leaves(l(X), [X]). leaves(b(X,Y), L) :- leaves(X, A), leaves(Y, B), append(A, B, L). So leaves will always return a flat list, even if there's just one. This also assumes your tree is strictly binary, as you have it described.

Categories : List

How to Turn Sharepoint lists into dropdown lists?
What about JavaScript with http://spservices.codeplex.com/wikipage?title=$().SPServices.SPCascadeDropdowns&referringTitle=Documentation ?

Categories : Forms

R extracting members of lists and sub-lists (S4 class)
Try this... W <- lapply( sim , function(x) `@`( x , W)[[1]] ) V <- lapply( sim , function(x) `@`( x , V)[[1]] ) You'll get a list of the first W of each of the 5 top-level lists and the first V of each of the 5 top-level lists. The @ operator is used to access named slots in an S4 type object.

Categories : R

Finding common elements from two lists of lists
Convert the innermost lists of b into a set(s), and then iterate over a to check whether any item in a exist in s or not. tot_items_b = sum(1 for x in b for y in x) #total items in b Sets provide an O(1) lookup, so the overall complexity is going to be : O(max(len(a), tot_items_b)) def func(a, b): #sets can't contain mutable items, so convert lists to tuple while storing s = set(tuple(y) for x in b for y in x) #s is set([(41, 2, 34), (98, 23, 56), (42, 25, 64),...]) return any(tuple(item) in s for item in a) Demo: >>> a = [[1, 2, 3], [4, 5, 6], [4, 2, 3]] >>> b = [[[11, 22, 3], [12, 34, 6], [41, 2, 34], [198, 213, 536], [1198, 1123, 1156]], [[11, 22, 3], [42, 25, 64], [43, 45, 23]], [[3, 532, 23], [4, 5, 6], [98, 23, 56], [918, 231, 526]]] >>&g

Categories : Python

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

Can i create lists of lists using Core Data
There's nothing wrong with your approach. Just be careful when setting what happens to dependents in the event of record deletion to avoid circular deletion. A cleaner way would be to create a listItem table that contains a boolean field to indicate whether the item is associated to list or track, then have has_one relationship with list and track. List table will contain listItems and listItems will manage what it contains. It's same as yours except it adds a design separation that makes it easy to deal with dependencies.

Categories : IOS

'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

Reverse search a lists of lists
You could do the opposite of an in-order search, have the method return wether the child needs to be removed. Rewrote the order to actually be reverse. Or add a reference to the parent in the child, yes that costs extra memory, which is why you almost always have to traverse the tree. public class Tree { private static Random rand = new Random(); public List<Tree> Children = new List<Tree>(); public Tree Parent; public string Name; public Tree(Tree parent) { Parent = parent; Name = rand.Next(10000).ToString(); } // Removing without tree traversal. public void DeleteParent() { this.Parent.Parent.Children.Remove(this.Parent); } public bool Remove(string name) { for(int i = Children.Count - 1

Categories : C#

Need some help learning jbox2d
I think your entities do not collide because you are using empty polygon shapes. shape = new PolygonShape(); You have to define the points of your Polygone shape so that jbox can test collision of the shapes. Something like this: Vec2[] vertices = { new Vec2(0.0f, - 10.0f), new Vec2(+ 10.0f, + 10.0f), new Vec2(- 10.0f, + 10.0f) }; PolygonShape shape = new PolygonShape(); shape.set(vertices, vertices.length); Further if you don't need gravity then just set the gravity vector to 0,0 Vec2 gravity = new Vec2(0f, 0f);

Categories : Java

Learning archiving
Using an NSKeyedArchiver to save simple application's setting is a bit overkill. The Foundation framework provides the NSUserDefaults class, which is much easier to use. This is the way to go, for iOS or OS X. It will write a plist file in the correct location with your settings. Writing something is basically: [ [ NSUserDefaults standardUserDefaults ] setBool: YES forKey: @"SettingsKey" ]; [ [ NSUserDefaults standardUserDefaults ] setInteger: 42 forKey: @"SettingsKey" ]; [ [ NSUserDefaults standardUserDefaults ] synchronise ]; The last line ensure data is written to disk. It's not mandatory, as it's invoked automatically at regular intervals, but it's usually safer to call it explicitly. Getting data is basically: [ [ NSUserDefaults standardUserDefaults ] boolForKey: @"SettingsKey

Categories : Iphone

Learning of SVM Code
image is an empty 3 channel matrix data, i.e. 512x512; R-G-B channels. At the end, this code draws the responses (predictions of SVM) onto that image - image at somewhere = green = (0,255,0). it is done in a for loop to create the lines from pointwise assigning. the SVM model training is an internal process of this method, in which opencv uses a learning algorithm that can be found only looking at the source code. however, it is declared and described in the documentation that the parameters like svm_type, kernel_type, k_fold, grid, balanced, ... changes the behaviour of the method.

Categories : Opencv

Supervised Learning
A good place to start is the weighted majority algorithm, which develops the weights for your detectors, based on their relative performance over a data set. There are variations of this algorithm, some of which can handle targets that drift over time. If your detectors are all instances of the same model (with different parameters), you could also take a look at the various ensemble learning algorithms, although these may be less applicable if your interest is in comparing the relative performance of your base algorithms.

Categories : Machine Learning

Learning SVN properly
This link http://svn.haxx.se/dev/archive-2010-01/0211.shtml strongly suggest that even after triple checking the url it is probably wrong. Btw: most subversion repositories behind a http server have longer url's. For instance http://svnserver.insomedomain.com/svn/svnrepository/trunk/project or http://svnserver.insomedomain.com/svn/svnrepository/tags/project/v1.0

Categories : Svn

Learning .prototype
The prototype is used to search properties when the object itself doesn't have it defined, during reads. Writes always happen on the object itself When you call // An instance of Foo ({prop1:0}) is set as the // prototype (to all instances of Goo) var goo = new Goo(); // 0, from the prototype console.log(goo.prop1); // Read from the object itself (set in Goo's constructor) console.log(goo.prop2); // New instance, same prototype as goo var goo2 = new Goo(); console.log(goo2.prop1) ; // 0, still from the prototype // Setting is always at the object level, not the prototype goo.prop1 = 5; // goo2 is still reading from the prototype console.log(goo2.prop1); N.B. Don't instantiate the parent class just to setup inheritance. See why here http://js-bits.blogspot.com/2010/08/javascr

Categories : Javascript

Learning how to use scrollview and autoresizing
You can use the didRotate methods to position your buttons how you want in the different orientations. There is a good tutorial here: http://www.youtube.com/watch?v=f3yb24f8O1Y&list=PL53038489615793F7

Categories : IOS

Persistent learning in pypy
No, that's basically not possible. What is possible is to get the result you want with workarounds: for example, turn your program into a local "server" which waits for requests (done from executing a 5-lines script), and serves them by doing the job of execute(). It's certainly not the most elegant solution but it lets all the execute() be done by the same process, with (after a while) the same speed-ups that you measured.

Categories : Misc

reverse() and learning pointers
In C++, you have a better, cleaner, safer, easier and more readable option - std::string. Here is a simple example of a function reverse() that returns a reversed std::string: void swap(string& str, int index1, int index2) { char temp = str[index1]; str[index1] = str[index2]; str[index2] = temp; } string reverse(string str) { int size = str.size(); for (int i = 0; i < size / 2; i++) swap (str, i, size - i - 1); return str; }

Categories : C++

learning AWS components and tutorials
Not sure what your use case is or coding background, but if PHP here's a nice start: http://docs.aws.amazon.com/aws-sdk-php-2/guide/latest/index.html Also try YouTube AWS channel as suggested above. The various heads of the web service groups post videos and webinars.

Categories : Amazon

Learning Map / Syllabus Visualization
Looking at the D3 examples. These two below look like good candidates for representing the content of a syllabus. http://mbostock.github.io/d3/talk/20111116/pack-hierarchy.html http://mbostock.github.io/d3/talk/20111116/force-collapsible.html I'm trying to do the same for my class. Will attempt to use the ones above. In the pack-hierarchy one, it is nice that it is zoomable. While in the force-collapsible one, it is nice to be able to collapse subjects. Somehow a graph representation, might be better than a hierarchy for a syllabus... Luis

Categories : D3 Js

Learning Pipes and Processes
You aren't passing your program's command-line arguments through to the "cat" child process. You initialize arrayOfCommands like so -> char *arrayOfCommands[] = {"cat", NULL}; <- then you pass it as-is to the execvp() function as the second argument.

Categories : C

Can I use unity 3d or udk while learning LWJGL?
LWJGL and UDK/Unity are very different beasts. LWJGL is a low level API from which you could build a game engine, while the UDK and Unity are complete ready-made game engines from which you can start building games without having to care about low level stuff like OpenGL/DirectX, Input controls, Audio, etc. So these engines will not help you to learn LWJGL but they might give you some ideas on how to do certain things (e.g. how to organize scenes, what formats to support, how to do an asset pipeline, etc.). If your ultimate goal is to actually write a game, I'd say go for one of the engines directly and don't bother with the low level stuff and LWJGL. Writing a game engine is hard to do and the engines out there cater for most types of games. If you have super-special needs or just want

Categories : Unity3d

Prerequisites for learning MFC programming
The most important prerequisite for learning MFC is C++, followed by unterstanding how Windows works. My favorite MFC book is Inside Visual C++ by David Kruglinski, who died too early. His last edition covers MFC with Visual Studio 6, but the concepts and most of the content are still valid. To see how Windows works, the "Petzold" is the book. (Windows Programming by Charles Petzold).

Categories : Windows



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