w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Iterating over list of list elements and returning error message if integer has certain value
Use the any() function with a generator expression testing each nested list: if any(bread[2] > 80 for bread in breadsticks): print("You have entered too many breadcrumbs") This will only test as many nested lists as needed to find any for which the test is True. Note that it is simpler to just loop directly over breadsticks in loops: for bread in breadsticks: print(bread[2])

Categories : Python

c# List.Contain(List) not returning true for containing list
To compare the lists, use SequenceEqual (MSDN) In your case, you can combine it with Any: var containsListToFind = parentList.Any(x => x.SequenceEqual(listToFind)); Contains won't work because it uses the default .Equals method of the objects in the list. For List<T>, that is a reference comparison, not a value comparision. Since listToFind is a different object than the one in parentList, the references are different and Contains won't find anything.

Categories : List

Returning a list to another list from a for-loop
I think you want to do something like this: >>> def list_of_list(): ... all_lists = [] ... for _ in range(3): ... all_lists.append([1, 2]) ... return all_lists ... >>> >>> list_of_list() [[1, 2], [1, 2], [1, 2]] I've just appended [1, 2] everytime for demonstration purpose. You can add any list there.

Categories : Python

Returning A> from builder
Is ParameterDefinition a generic class? In other words, is it defined as public class ParameterDefinition<T> or something other than public class ParameterDefintion If so, then you can return a ParameterDefintion<List<String>>, but if not, you need to decide on what value to place within the <T> area. By the way, adding final to a static method has no effect, and is redundant. I'd remove it. After ParameterDefinition takes a Generics parameter, you can write public static final <X> ParameterDefinition<X> build(Class<X> clazz, String name) { ... return ...; } And you don't even need the cast you had at (ParameterDefinition) ParameterDefinition.build( List.class, "names" );

Categories : Java

mvc 4 complex list returning null
You can create a partial view for ActivityService and render this in foreach: In your actual view: @foreach(ActivityService item in Model.ActivityServices) { @Html.Partial("ActivityService", item) } In a new partial view ActivityService.cshtml: @model Proyect.Models.ActivityEditViewModel.ActivityService @Html.HiddenFor(m => m.ServiceID) @Html.LabelFor(m => m.OutcomeComment) @Html.TextBoxFor(m => m.OutcomeComment)

Categories : Asp Net Mvc

Returning a list from an SNMP agent
I'm have little experience using NetSNMP package, I use NET::SNMP, but if you can collaborate more on what exactly you are trying to achieve and post some sample code or specific OID references I might be able to help you...

Categories : Perl

List Foreach returning booleans
Use the IEnumerable<T>.All extension method, which returns true if all elements of a sequence satisfy a condition: List<int> ints = new List<int> { 1, 2, 3, 4, 5 }; bool result = ints.All(x => x > 0); // true if all items are > 0

Categories : C#

Removing and returning value from linked list
Use some local memory for storing data and return it after deletion. int i; int data = 0; //for storing data node *tmp = head; for(i=0 ; i<pos && tmp != NULL; i++) //Added for checking end of list tmp = tmp->next; node* tmp2 = tmp->next; tmp->next = tmp->next->next; data = tmp2->data; //copy data to local struct before deleting free(tmp2); return data; //return the data

Categories : C

Returning a generic list in java
I have code that looks exactly like this that is used by an ExtJS front-end, so I'm kinda making a guess that you are doing something similar. My Response object just wraps an Object. public class Response { public static Response createSuccess(Object data) { return new Response(true, SUCCESS_MSG, data); } public static Response createFailure(String msg) { return new Response(false, msg, EMPTY_LIST); } private boolean successful; private String message; private Object data; // ... } Then my web tier is written using Spring MVC which is configured to serialize the Object to a JSON string when it returns the response. But my whole server-side manipulates domain objects, rather than passing around/parsing json. @RequestMapping(method = Reques

Categories : Java

Returning a value from Kendo drop down list
You can get the text value through the text property like this: var selectedText = $("#typeDropDownList").data("kendoDropDownList").text()

Categories : Jquery

List comprehension returning values plus [None, None, None], why?
print is a function (in Python3). It prints something to the screen, but returns None. In Python2, print is a statement. [print(x) for x in g] would have raised a SyntaxError since only expressions, not statements, can be used in list comprehensions. A function call is an expression, which is why it is allowed in Python3. But as you can see, it is not very useful to use print in a list comprehension, even if it is allowed.

Categories : Python

Custom django tag returning a list?
This looks perfectly fine to me. Alternatively, for some reason if you cannot pass the product_list through the view's context, you can use an inclusion tag if you feel that is cleaner: @register.inclusion_tag("tags/products_list.html") def all_products(): return {'product_list': Product.objects.order_by('name') } products_list.html {% for product in products_list %} ... {% empty %} Empty list {% endfor %} and in the html file, you would just do {% all_products %}

Categories : Python

Returning a List of type from web service
In the "Add Service Reference" dialog, click "Advanced" and choose to use List<T> as the collection type.

Categories : C#

Items.Count returning 0 for a list box
I am going to guess that you do not have any logic in your Page_Load to populate the listbox, based upon what it had when you finished the autocomplete extender logic. Since, you do not, then when the click event fires after the Page_Load your values are gone. Put the logic that executes on selection of the autocomplete extender in a method and have your Page_Load call that, like this: Protected Sub Page_Load(sender As Object, e As EventArgs) ' Put call here to populate the listbox results from autocomplete extender selection PopulateListBox() End Sub Private Sub PopulateListBox() ' Go to whatever resource you are using to get the values for the list box End Sub UPDATE: Since you are depending upon using a client-side function to grab the values from the autocomplete exte

Categories : Asp Net

hql - returning single object instead of list?
No, it will still return a collection for you to iterate over - but you can use uniqueObject to get a single result instead. That will throw an exception if it turns out there's more than one result.

Categories : Java

returning initializer list mechanism
There are no performance penalties involved. The return value is constructed equivalent to std::array<int, 3> x = { 1, 2, 3 }; There is not even a single copy or move of an std::array instance involved.

Categories : C++

Linux Script: Returning a range when given list
The problem is that you inverted the order on the g1 and g2 assignment! Here's your script working: #!/bin/bash read -p "Enter NUM1 " NUM1 read -p "Enter NUM2 " NUM2 if [ $NUM1 -gt $NUM2 ]; then g1=$NUM1 && g2=$NUM2 elif [ $NUM2 -gt $NUM1 ]; then g1=$NUM2 && g2=$NUM1; fi for VALUE in $@; do if [ $VALUE -lt $g1 ] && [ $VALUE -gt $g2 ]; then COUNT=$((COUNT+1)); fi done echo $VALUE happened $COUNT times

Categories : Shell

Python list append returning odd results
This is because lists are by reference and you re-use y. When you append y to circs, circs gets another reference to y. When you later modify y, you will see the change in each spot in circs where y was appended. Try making a copy of y and working with that. def getcircs(mylist): circs=[] x=mylist y=list(x) dig=len(x)-1 j=0 circs.append(x) while j < dig: temp = y[:] for i in range(0,dig): r=i+1 g=x[r] temp[i]=g temp[dig]=x[0] print temp circs.append(temp) x=list(temp) j+=1 print circs return circs The line temp = y[:] just creates temp as a full slice of y, which natively produces a copy.

Categories : Python

Recursion: Returning a list in order traversal
The key thing is how can we determine when this recursive function actually ends Like ordinary functions, recursive functions end as soon as the top level of its invocation returns. The problem with your function is that it tries to both construct a list, and return it; it should do one or the other. Constructing the list is simple - make your function void, and change it as follows: void inorder(Node *root, vector<int>& listToAdd) { if(root != NULL) { inorder(root->left, listToAdd); listToAdd.push_back(root->data); inorder(root->right, listToAdd); } } That's it! The two changes I made was taking the argument by reference, and returning void. Call your function as follows: vector<int> inorderList; inorder(myNode, inorderLi

Categories : C++

Python - Returning list/ arry from function
You are returning the first device you match. Build a list instead and return that list: def find_usb(self): bus = dbus.SystemBus() ud_manager_obj = bus.get_object("org.freedesktop.UDisks", "/org/freedesktop/UDisks") ud_manager = dbus.Interface(ud_manager_obj, 'org.freedesktop.UDisks') found = [] for dev in ud_manager.EnumerateDevices(): device_obj = bus.get_object("org.freedesktop.UDisks", dev) device_props = dbus.Interface(device_obj, dbus.PROPERTIES_IFACE) if device_props.Get('org.freedesktop.UDisks.Device', "DriveConnectionInterface") == "usb" and device_props.Get('org.freedesktop.UDisks.Device', "DeviceIsPartition"): if device_props.Get('org.freedesktop.UDisks.Device', "DeviceIsMounted"): device_file = device_p

Categories : Python

Apache Thrift: Returning a list/container
I accidentally came across an article (StackOverflow: Handling Apache Thrift List Map Return Types in C) that discussed this exact issue (though the answer didn't work in my case). Turns out, thrift uses a pass-by-reference syntax, even though "Thrift uses a pass by value model" - Gupta. So here's an example: .thrift file service Test { list<string> ping(); } Server side void ping(std::vector<string> & _return) { _return.push_back("hello"); //initialize the vector _return with values "hello","world" _return.push_back("world"); } Client side std::vector<string> result; //create vector "result" for storing the values client.ping(result); printf("%s %s! ", result[0].c_str(), result[1].c_str()); //c_str() turns the vector string into a C-styl

Categories : List

Use SELECT DISTINCT in createQuery returning a list value
When you start your query with FROM TblTaxType OR Select * it returns the table rows with all your table Columns and assigns it to the list with List <TblTaxType> DataType hence it doesn't give any error. But when you write Select colName it returns only the string present in that table cell. Which it can't convert to java.lang.String cannot be cast to com.test.test.classes.TblTaxType There is no Problem in Using Distinct in Hibernate. See here :- How do you create a Distinct query in HQL

Categories : Java

Jquery dropdown list value returning undefined
Try this, $(function(){ $("select#ddlFullName").change(function () { console.log("changed"); var selectedText = $(this).val(); console.log("selected text= " + selectedText); }); });

Categories : C#

Joining of two queries and returning in list format
The reason you can't union them is that the two lists return different objects. The first list returns an anonymous type with members Name and Id. If, instead, you just wanted to return the purchase orders in query one, then you could simply use the following: var poList = ( from po in db.PurchaseOrders where po.CompanyId == companyId && po.PartyId == partyId && (po.IsDeleted == false || po.IsDeleted == null) select po ); You may need to append .ToList() to the query above in order to use the Union(...) method. Then, you should be able to union the two sequences together (assuming poList2 is also a sequence of db.PurhaseOrders objects. Conversely, instead of changing query for poList above, you could change the query behind poList2 to

Categories : Asp Net Mvc

Function returning list of different possible children classes
Yeah, as Sayse says, you need yourself an interface and/or an abstract class. If there's a lot of shared code, you can just start with the latter. Here's something riffed on from an old test project. It takes a different approach (each item in the collection is what's relevant as the 'dirty' thing, and there are excised methods that would search the collection for those), but you should be able to adapt as needed: [DataContract] public abstract class Dirty : Object { protected bool _isdirty; public bool IsDirty { get { return _isdirty; } set { _isdirty = value; } } public abstract class DataStore<T> where T : Dirty { private string _path; private string _tempFile; protected DataStore(string path, string tempfile)

Categories : C#

Casting objects when returning a generics list
Actually the answer is simpler than you think : you just have to check whether your instance of Content is a Show or a Movie to make your compiler happy : if (content instanceof Movie) contents.add((Movie) content); if (content instanceof Show) contents.add((Show) content); Anyway, I would say that the way that you wrote your generic method is correct. But since there is a native way to check for the type of an instance (instanceof), you should use it :) EDIT : I still think you should use instanceof. Plus, you should use a List<Content> instead of a List<ContentIniter>, because Content is a more global type : if someone comes up with another implementation of Content, he won't have to change your code. Actually, you're doing the same thing when you use the Interfa

Categories : Java

CAML Query on a SharePoint list is returning the ID and the value - how to just get the value?
This is the way SharePoint returns the value. I would just use a regular expression to replace the value var newValue = value.replace(/^d+;#/,""); This will look at the beginning of the string for a number followed by a semicolon and hashmark, and replace it with nothing. Using your value above var value = "91;#Doe" var newValue = value.replace(/^d+;@/,""); will remove 91;# and assign Doe to newValue.

Categories : Javascript

Returning first occurrence index of a number in a list
def bounce(tickList,x): n = 0 for i in tickList: if float(i[1]) < x: return n # return float(i[1) n += 1 return None something like this???

Categories : Python

Sharepoint: GetList listName returning all list
Solved it so I'm going to post for others to reference: The problem was in my NSMutableURLRequest: NSMutableURLRequest* theRequest = [[NSMutableURLRequest alloc]initWithURL:locationOfWebService]; NSString *msgLength = [NSString stringWithFormat:@"%d",[soapFormat length]]; [theRequest addValue:@"text/xml" forHTTPHeaderField:@"Content-Type"]; [theRequest addValue:@"http://schemas.microsoft.com/sharepoint/soap/GetListItems" forHTTPHeaderField:@"SOAPAction"];//<--make sure you change this line to the web service query you are using (in this case GetListItems [theRequest addValue:msgLength forHTTPHeaderField:@"Content-Length"]; [theRequest setHTTPMethod:@"POST"]; //the below encoding is used to send data over the net [theRequest setHTTPBody:[soapFormat dataUs

Categories : Objective C

Method without parameters returning List in Web services
You can get a JSON from your List and send the array of bytes of the JSON's file. And in the calling method you get that array of bytes, create a temp file (if it's necessary), get the List from the JSON's file. I do this is my application between Android and Java, and it's working fast than send the Object, because I zip the file too. []s William Bertan

Categories : Java

Traversing the Ordered List backwards returning each li text
Here; I'll show a down and dirty method to get you rolling, then you can find a better way (maybe using textContent)... $('li').click(function(e){ var parents = $(this).add($(this).parents('li')) .map(function(){ return $(this).clone().children().remove().end() .text().replace(/ | |^s+|s+$/g,''); }) .toArray().join('/'); alert(parents); e.stopPropagation(); });

Categories : Javascript

AWAIT / ASYNC example of background worker returning List
The reason you haven't seen examples of using async with synchronous code is because async is for asynchronous code. That said, you can use Task.Run as an approximate replacement for BackgroundWorker. Task.Run enables you to take synchronous code and consume it in an asynchronous way: main() { List<string> resultSet = await Task.Run(() => CreateList(dirPath)); console.out(resultSet.ToString()); } public List<string> CreateList(string dirPath); { //do some work on dirPath NOT CALLING ANY ASYNC methods return LIST<STRING>; } I'm currently going through a series on my blog on replacing BackgroundWorker with Task.Run, which you may find helpful.

Categories : C#

ServletFileUpload.parseRequest() returning an empty list for MockMultipartHttpServletRequest
I had the same issue...the following approach worked for me. http://devnotesblog.wordpress.com/2010/06/17/mocking-a-multipartform-data-http-request-in-a-unit-test/

Categories : Java

Returning a list of numbers from a loop inside a function
The NSArray data type is the basic array type in Objective-C. The NSMutableArray represents the mutable array type. Arrays can only store objects, not primitive types such as int, so the items need to be converted to NSNumber objects before being added to the array. #import <Foundation/Foundation.h> NSArray* erathos (int n){ int i, prime, multiple, P[n]; for (i = 2; i <= n; ++i) { P[i] = 1; } for (prime = 2; prime <= n; ++prime) { if (P[prime]) { for (multiple = 2 * prime; multiple <= n; multiple += prime) { if (P[multiple]) { P[multiple] = 0; } } } } NSMutableArray* array = [NSMutableArray array]; for (i = 2; i <= n; ++i) { if (P[i])

Categories : Objective C

Returning list using @Responsebody or return ModelAndView from spring controller which one better
Viswam, The answer depends mostly on your application and the functionality you want to achieve, there is no standard solution here. If your application is a single page application (read this wikipedia article) or you want RESTful application, I would suggest to stick with @ResponseBody, reason is simple, it supports AJAX and basically doesnt change the page from Server side. You can easily populate any complex table using plain JavaScript or jQuery from the JSON response you receive. Also if I were to think, I wouldn't want to waste my resources at server side for populating data in JSP and then send it over to client(browser) when it can do this by itself. But this is strictly a personal choice/preference. And, If you need to redirect to or reload a page, I believe ModelAndView is

Categories : Java

Returning a list of indices where a certain object appears in a nested array
Nothing super-elegant comes to mind for me right now. This seems to work: def indices_of(board, letter) indices = [] board.each_with_index do |ar, i| ar.each_with_index do |s, j| indices.push([i, j]) if s == letter end end indices end boggle_board = [["P", "P", "X", "A"], ["V", "F", "S", "Z"], ["O", "P", "W", "N"], ["D", "H", "L", "E"]] indices_of(boggle_board, "P") # => [[0, 0], [0, 1], [2, 1]]

Categories : Ruby

Returning a length from a list of divs, with exceptions to its children not having a certain attribute value
$(data).find('.project-img-container').children().filter(function() { return !$(this).find('[alt="Missing"]').length; }); FIDDLE or just: $(data).find('.project-img-container').children(':has([alt!="Missing"])');

Categories : Javascript

Filter Null then Return Message in List or TextView Vs Returning Nothing
This question answered it: http://stackoverflow.com/a/3771631/350421 Just put this: <TextView android:id="@android:id/empty" android:layout_width="match_parent" android:layout_height="match_parent" android:text="No Results" /> ...in your XML layout. Mine turned out like this: <TextView android:id="@id/android:empty" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_below="@+id/tv" android:gravity="center" android:text="No Results... Scan next item." //use @string here... android:textSize="20sp" />

Categories : Android

Saving contents of String Array List when moving to a new activity and returning to the previous one
You should use PersistentState of app (SharedPreferences) So make the onPause() method on your activity and there save SharedPreferences SharedPreferences settings = getSharedPreferences("key", MODE_PRIVATE); SharedPreferences.Editor editor = settings.edit(); editor.put.... Then onCreate check for SharedPreferences.contains("key"); and reload data from there with SharedPreferences settings = getSharedPreferences("key", MODE_PRIVATE); settings.get...

Categories : Java

How to remove 'Type Safety'/'Unchecked conversion' warning from returning generic List in Java?
Since you put the spring tag in your question I assume that you are already using Spring. In that case using SpringData and JPA instead of Hibernate-specific stuff would be much easier. Otherwise you can't really get rid of the warning because you can't change the api.

Categories : Java



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