w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories
Why does adding a list to another list, using add range, remove the elements from the first list?
It's because of the IEnumerable. When you set groupsToAdd to the result of groups1.Where(g => false == groups2.Contains(g)) there is deferred execution, which means that the query is not run until AddRange() and then again at Dump(). Because the list, groups2, now contains the elements they no longer are a result of the original query.

Categories : C#

Adding checked items in a custom list view to array list in android
initialize the "ArrayList" ArrayList<List> selectedItems; protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_home_page); selectedItems = new ArrayList<List>(); }

Categories : Android

conditionally adding multiple items to a list of lists via python list comprehension
The line html = BeautifulSoup(urllib2.urlopen('http://domain.com').read(), 'lxml') implies you have lxml installed, so you could use an XPath using | to pull out text or attribute values: import urllib2 import lxml.html as LH html = LH.parse(urllib2.urlopen('http://domain.com')) clean_data = [[elt for elt in tr.xpath('td/a/text() | td/a/@href | td/text()')] for tr in html.xpath('//table[@id="targeted_table"]/tr')] print(clean_data) yields [['http://domain.com', 'data 01', 'data 02', 'data 03', 'data 04'], ['http://domain.com', 'data 11', 'data 12', 'data 13', 'data 14'], ['http://domain.com', 'data 01', 'data 22', 'data 23', 'data 24'], ['http://domain.com', 'data 01', 'data 32', 'data 33', 'data 34']] You could also do it with a single call to the xpath met

Categories : Python

Selenium adding items from a Web element list to a string array list
Please try using following sample code, change xpath/data accordingly List<WebElement> resultList = _driver.findElements(By.xpath("//img[contains(@src,'tab-close.png')]/preceding-sibling::span[@class='tab-name ng-binding']")); for (WebElement resultItem : resultList){ String tabname=resultItem.getText(); if(resultItem.getText().equalsIgnoreCase("Dashboard")){ GlobalFunctions.clickOnButtonCustomised(false, _driver, By.xpath("//span[@class='tab-name ng-binding' and contains(text(),'"+tabname+"')]/following-sibling::img[contains(@src,'tab-close.png')]"), ""); } }

Categories : Java

knockoutjs - How to Create a List style app in with entry before adding list items
You are in fact very close to making it work. The problem was that you did not define the donationAmount observable property in the main view model, which resulted in KnockoutJS failing when binding this unavailable property to the input tag. Here is the part of the code that had to be changed so that it works now: function DonationsViewModel() { var self = this; self.donationAmount = ko.observable(); // .... } and here's some little change to your HTML: <div> <select data-bind="options: availableDonations, optionsCaption: 'Please select...', value: selectedDonation, optionsText: 'label'"></select> <input data-bind="value: donationAmount"/> <button typ="button" data-bind="click: addDonation">Add Donation<

Categories : Knockout Js

Adding specific items from a list to a new list, index out of range error
The simple fix is to wrap your append in a try catch statement. for item in stock_data: try: closing_prices.append(stock_data[count]) except IndexError: break print (closing_prices) count = count + 6 the reason you are getting to the error is that when you get to the 5th to the last item in the list then add 6 to it you are now out of range of the lists maximum index so to speak. Another possible solution is to use a while loop. closing_prices = [] count = 10 while count < len(stock_data): closing_prices.append(stock_data[count]) count += 6 print closing_prices

Categories : Python

python adding list inside list unexpected behavior
You are manipulating the same list over and over again, not a copy. Create a new list in the loop instead: for elemento in lista_base: listado = [elemento, elemento + 1, elemento + 2] tabla.append(listado) or create a copy of the list: for elemento in lista_base: listado[0] = elemento listado[1] = elemento+1 listado[2] = elemento+2 tabla.append(listado[:]) where [:] returns a full slice of all the elements. You could also use list(listado) or import the copy module and use copy.copy(listado) to create a copy of the existing list. Appending a list to another list only adds a reference, and your code thus created many references to the same list that you kept changing in the loop. You could have seen what was happening had you printed tabla on every loop. Pri

Categories : Python

Adding Sharepoint List Item to Windows form list
Completely untested, made fresh while drinking morning coffee. Good luck! var list = siteWeb.Lists.TryGetList(listName); if (list == null) { return; } var items = list.GetItems(query); var countOfItems = items.Count; if (countOfItems == 0) { return; } var listItemFieldObjects = items.Cast<SPListItem>().Select(item => item[1]); foreach (var item in listItemFieldObjects) { var listViewItem = new ListViewItem("Object's value"); listView.BeginUpdate(); listViewItem.SubItems.Add(item.ToString()); listView.Items.Add(listViewItem); listView.EndUpdate(); }

Categories : Sharepoint

Should adding a new item to a list<> update previous items in the list?
You're not adding several different items to the list, you're adding the same exact item several times and modifying it each time. Classes in C# are reference types; that means each variable doesn't hold the data for the object itself, it just hold onto a reference to where that object is. Assigning an object to another variable doesn't create a new object, it just copies the reference to that same object. The issue is that you should be creating a new object (i.e. using the new keyword) each time you go to add a new item to the list. From the looks of your code it would seem that StaticLists.GetStockMultibuyForBarcode(sBarcode) isn't returning a new item each time; it's just returning the same item, or at the very least one of the existing items. You should be creating a new item, co

Categories : C#

adding item to a list then have list appear in a Combobox
EDIT: I am going to assume this question is mis-tagged as WPF and is really about winforms in which case my answer doesn't make sense profselect.ItemsSource = datalist; (not DataSource) and indeed it probably should be outside the loop

Categories : C#

Adding to List on For Loop (What do I set the List to initially?)
You can use map with operator.add: >>> from operator import add >>> map(add,*dict1.values()) [3, 5, 7] >>> map(add,*dict2.values()) [4, 6, 8, 10] or zip with a list comprehension if you don't want to import anything: >>> [sum(x) for x in zip(*dict1.values())] [3, 5, 7] >>> [sum(x) for x in zip(*dict2.values())] [4, 6, 8, 10] Update: def func(dic, *keys): return [sum(x) for x in zip(*(dic[k] for k in keys))] >>> dict1 = {'a': [0,1,2], 'b': [3,4,5], 'c':[6,7,8]} >>> func(dict1,'a') [0, 1, 2] >>> func(dict1,'a','b') [3, 5, 7] >>> func(dict1,'b','c') [9, 11, 13] >>> func(dict1,'b','c','a') [9, 12, 15]

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#

Adding Sharepoint 2010 List Items to a List with external Items
One option is to create an SQL server trigger. This trigger would fire whenever a new sales order is created in your source database. You could make it a CLR trigger, and in the function make use of the SharePoint client interface. After you provided a clearer description of the problem: I believe that you're looking for something like the list event handler. This will run on the events you care about, and you can pull from the database at the appropriate time. Essentially, you need to make a Visual Studio SharePoint project (from my past experience this method requires you to use VS right on the SharePoint server, or else you have to copy a lot of DLLs manually from the server); and make an event receiver.

Categories : SQL

Adding one element from a list to next,after that to next etc
Use sum() to add up all values of a sequence: >>> sum([2,5,9,12,50]) 78 But if you wanted to keep a running total, just loop through your list: total = 2 for elem in newlist: total += a print total That also can be used to build a list: total = 2 cumsum = [] for elem in newlist: total += a cumsum.append(total)

Categories : Python

Adding to a list box on another form
First of all, did you make the listbox public? I believe you can do this by selecting the listbox, going to the properties window, finding the Modifiers item, and setting it to Public. Second, make sure the form that contains the list of employees, is static, and that you're not creating the same form each time you want to add an employee. Do this by: namespace WindowsFormsApplication1 { public static class Program { public static EmployeeCumalitveList MyEmployeeList; /// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); MyEmployeeList =

Categories : C#

Getting a 2-D list and adding each column
You can use numpy to get the column sum import sys import numpy ROWS = 3 COLS = 4 def main(): global ROWS global COLS matrixData = [] # Get input and process it for i in range(0, ROWS): thisRow = raw_input('Enter a 3-by-4 matrix row for row ' + str(i) + ' : ').split() evalRow = [] [evalRow.append(eval(element)) for element in thisRow] matrixData.append(evalRow) numpyMatrix = numpy.array(matrixData) colSums = [] [colSums.append(numpy.sum(numpyMatrix[:,index])) for index in range(0,COLS)] # Print the matrix for row in matrixData: print row print colSums return if __name__ == '__main__': main() sys.exit(0)

Categories : List

c - Adding new item to a list
EDIT: I got a bit carried away with this (it's a slow day at work) so I rewrote the function to use (IMHO) clearer variable names, fewer redundant variables, and added basic error handling. The example below supports insertion whereas the previous example assumed simple appending to the end of a list which was the result of not reading the question properly (see edits if you're curious). void listAdd(Node* currentNode, Node toAdd) { Node * newNode = malloc(sizeof(Node)); if(!newNode){ //ERROR HANDLING } * newNode = toAdd; newNode->next = NULL; while (currentNode) { if(!currentNode->next) //We've got to the end of the list without finding a place to insert the node. //NULL pointer always evaluates to false in C regardless

Categories : C

Adding the same elements into a list
If I run your script, I get the following output [2, 4, 5, 7, 6, 7] [2, 3, 4, 4, 4] There is only one 4 deleted from B because you removed an element while running over the list. Maybe you should remove the 4's from B after looping over B. A = [2,3,4,4] B = [2,4,4,5,7,6,7] for i in B: if i == 4: A.append(4) B = filter(lambda a: a != 4, B) print B print A

Categories : Python

Adding an item to a list,from the keyboard
You can't. You could write a function that reads an int from cin and returns it, and then write list.addNode(readInt()); But the function that does the read still needs a local variable to read into.

Categories : C++

Adding elements to unordered list
Try with $description.each(function() { $("#list").append("<li>" + $(this).text() + "</li>"); }); DEMO

Categories : Jquery

Adding List to DataTable
First you need to spit the string appropriately to get a list of string arrays. Something like this: var patient_list = new List<string[]>(strMLMPatientData.Split(';').Select(x => x.Split(','))); or even better: var patient_list = strMLMPatientData.Split(';').Select(x => x.Split(',')).ToList(); You need Linq for that, but you get the idea. Then you need to add columns to your data table. You cant add rows to it when there are no columns.. Try something like this in your function //add columns appropriately DataTable table = new DataTable(); table.Columns.Add("Name", typeof(string)); table.Columns.Add("Order", typeof(string)); table.Columns.Add("Date", typeof(string)); foreach (var row in patient_list) table.Rows.Add(row); return table; See an example here. As it

Categories : C#

Adding a -q switch to a list of arguments
Something jumped out at me right away, you're testing if the argument equals -q by if( strcmp( argv[1], "-q" ) != 0) //This is an example of what I am trying to do. { quiet = true; infile.open( argv[2] ); } which is incorrect. strcmp returns the lexical difference between the two strings compared : http://www.cplusplus.com/reference/cstring/strcmp/ so I believe you want if( strcmp( argv[1], "-q" ) == 0) //This is an example of what I am trying to do. { quiet = true; infile.open( argv[2] ); } Like I said, I haven't tested anything, it just jumped out at me. edit how I would parse in the sourcefile, destfile, and -q option std::string sourceFile; std::string destFile; if ( argc == 3 ) { sourceFile = std::string( argv[1] ); destFile = std::string( arg

Categories : C++

adding nested ul list from code behind
In the inner loop, you need to create a sub <ul> tag. foreach (TreeNode childNode in node.ChildNodes) { HtmlGenericControl child_li = new HtmlGenericControl("li"); navMenu.Controls.Add(child_li); becomes if(node.ChildNodes.Count > 0) { HtmlGenericControl child_ul = new HtmlGenericControl("ul"); li.Controls.Add(child_ul); foreach (TreeNode childNode in node.ChildNodes) { HtmlGenericControl child_li = new HtmlGenericControl("li"); child_ul.Controls.Add(child_li); etc...

Categories : HTML

Adding column to pyodbc list
it seems fairly straightforward - as the error message states you're trying to + two different types of objects. If you just cast the rows as lists it should work, so from my own ad-hoc testing: >>>cur.execute('<removed>') #one of my own tables >>>tmp = cur.fetchall() >>>type(tmp[0]) #this is KEY! You need to change the type <type 'pyodbc.Row'> >>>tt = [1,2,3] >>>tmp[0] + tt #gives the same error you have Traceback (most recent call last): File "<pyshell#13>", line 1, in <module> tmp[0] + tt TypeError: unsupported operand type(s) for +: 'pyodbc.Row' and 'list' >>>list(tmp[0]) + tt #returns a list as you wanted [14520496, ..., 1, 2, 3]

Categories : Python

Adding Elements to List Java
Arrays.asList returns a fixed-size List. Adding or removing elements from this list is not allowed, it is possible however to modify the elements inside this list using the set method. public static <T> List<T> asList(T... a) { return new ArrayList<T>(a); // this is not java.util.ArrayList } private static class ArrayList<E> extends AbstractList<E> implements RandomAccess, java.io.Serializable { ArrayList(E[] array) { if (array==null) throw new NullPointerException(); a = array; } public E set(int index, E element) { E oldValue = a[index]; a[index] = element; return oldValue; } // add() and remove() methods are inherited from AbstractList } public abstract class A

Categories : Java

Adding the numbers from a stringed list
You want to find the sum of all the lists, not from one specifically (as you have tried). Use a list comprehension instead of a for-loop: total2 = sum(int(i[2]) for i in dL if '2011' in i) To get the average: average = total2 / float(len([int(i[2]) for i in dL if '2011' in i])) # In python 3, the float() is not needed A list comprehension is a quick way to make a list. Take for example this: result = [] for i in range(1, 4): result.append(i**2) Result will contain: [1, 4, 9] However, this can be shortened to a list comprehension: [i**2 for i in range(1,4)] Which returns the same thing. The reason for when I call sum() and I don't put in brackets around the comprehension is because I don't need to. Python interprets this as a generator expression. You can read more abou

Categories : Python

adding files to a list in a method
I'm an idiot. I was declaring the list inside the method that calls GenerateEmployeeApplication() - I'm guessing once I step out of that the list is kaput. I moved the declaration outside any methods and it retains the information. sorry for wasting everyone's time!

Categories : C#

Adding(removing) data from XML to list
Your Question is not very clear to me. Following is the solution what i made up from your question. <?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"> <fx:Script> <![CDATA[ import mx.controls.Alert; private var lastId:int = 5; private function addNode():void { var suffix:int = int(Math.random()*100000); lastId++; var node:String = '<person id="'+lastId+'" >' + '<firstName>FirstName'+suffix+'</firstName>' + '<

Categories : Actionscript

Nullpointer exception when adding to list
Why do you need to do all this? Why isn't this sufficient? // This has your data in it. List<Gladiators> gladiators = new ArrayList<Gladiators>(); // Obviously some attributes, including a unique key or name. // MUST override equals and hashcode properly Gladiator g = new Gladiator(); if (gladiators.contains(g)) { // do something here. } NullPointerException is one of the easiest problems to fix. Run your code in an IDE with debugging turned on and put a breakpoint where the stack trace says the exception occurred. You'll figure out quickly why something you assumed should not be null has violated your assumptions.

Categories : Java

C# adding to list object from checkbox
First: Fetch existing Packages from your database: public function GetPackages() as List<Package> { using (var connection = my_DB.GetConnection()) { try { connection.Open(); SqlDataReader rdr = null; dt = new DataTable(); string CommandText = "SELECT ID, Name FROM TABLENAME WHERE UPPER(Import_File_Source) LIKE '%abc%' and STATUS = 1"; SqlCommand cmd = new System.Data.SqlClient.SqlCommand(CommandText, connection); var packages = new List<Package>(); using(var reader = cmd.ExecuteReader()) { do while(reader.Read()) { packages.Add(new Package({ID = reader.GetString(0), Name = reader.GetString(1)}) }

Categories : C#

Adding to a list inside a class
You need to initialize your list in the constructor: public User (string username) : this() { _name = username; } public User() { this.ControlNumber = new List<int>(); } Otherwise, ControlNumber will have its default value of null.

Categories : C#

Adding drop down list from tutorial
The @Html.DropDownList() is a little bit special. You can either pass it a parameter value implicitly or explicitly. In the tutorial, they are doing it implicitly by calling the helper with the name of the model property, like so: <div class="editor-field"> @Html.DropDownList("DepartmentID", String.Empty) @Html.ValidationMessageFor(model => model.DepartmentID) </div> By doing it implicitly, the HTML-helper will look in the ViewBag for an object with the same name. And, as you can see in the PopulateDepartmentsDropDownList() method they are doing exactly that (last line): private void PopulateDepartmentsDropDownList(object selectedDepartment = null) { var departmentsQuery = from d in db.Departments orderby d.Name

Categories : C#

Exception when adding list to ObjectListView
Answer: The properties are set to private, and they should've been public. Once I switched that around, all was well. Credit goes to drch on the C# chat for this amazing answer.

Categories : C#

Adding to front of List throws?
You can't add element to a list created using Arrays.asList(). As the documentation explains: Returns a fixed-size list backed by the specified array.

Categories : Java

Adding methods to a list in Scala
this is not a correct syntax () => println("x") :: l2 the correct one is (() => println("x")) :: l2 and why l2 = foo :: l2 does not compile is because the type of foo does not compliant with l2 to understand it deeply try following foo.toString however followings will be compiled var fn = {() => println("y")} l2 = fn :: l2 or foo _ :: l2

Categories : Scala

Adding linked list to constructor
this -> //trying to add linked list here should be: this ->inventory(); //trying to add linked list here A few things of note: you don't need this-> in front of members. your code will be better (smaller and more efficient) if you use initializer lists Example: player::player(): name("default"), lvl(99), // and so on inventory() { } The members of your player class should (probably) be private

Categories : C++

how can i insert list of ids while adding records?
Since you need to link the old and new id's, you will need a different approach than the one used here. When you generate the new question records, store the id's in a structure, rather than an array, so you can maintain a mapping of old => new values. <!--- initialize mapping of old => new ids --> <cfset idMapping = {}> <cfloop ...> <!--- use the "result" attribute to capture the new id ---> <cfquery result="addRecord" ....> INSERT INTO YourTable (...) VALUES (...); </cfquery> <!--- save the id in the array --> <cfset idMapping[ oldQuestionID ] = addRecord.GENERATED_KEY> </cfloop> When you insert the new answers, use the old id to do a look up and grab the new ques

Categories : Mysql

Adding a scroll bar to a checkbox list
The div needs to be shorter then the content of the div. Since you haven't specified a height, it will be as tall as it needs to be to hold all the content. Add a height: some-length.

Categories : HTML

Adding list of classes to PHP array
Using array_shift to break up the array worked for me, but it does not work if $cats has mutliple classes <?php $classes = array(); $terms = get_the_terms($post->ID, 'product_cat'); foreach ($terms as $term) { $cats[] = $term->slug; } $classes[] = implode(" ", $cats); <li <?php post_class( $classes); ?>>

Categories : PHP

Retaining Indentation of the list after adding to PdfCell
This how I solved this. I know this is not a proper one.But it worked for me. I am adding a table with variable width in the first cell of the parent table i.e here pobjTable PdfPTable DummyTable = new PdfPTable(2); //Here the floatSpace value changes according to the lftBulletIndent values float[] headerwidths = { 2f + floatSpace, 98f - floatSpace}; DummyTable.SetWidths(headerwidths); Pcell = new PdfPCell(); Pcell.Border = Rectangle.NO_BORDER; DummyTable.AddCell(Pcell); Pcell = new PdfPCell(); Pcell.AddElement(list); Pcell.Border = Rectangle.NO_BORDER; DummyTable.AddCell(Pcell); pobjTable.AddCell(DummyTable);//Inserting a new table here pobjTable.AddCell("");

Categories : C#



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