w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
How to show inner content in list item outside of that list item without being covered up by descending list items
You must set the z-index of the clicked 'li' higher and in return the former clicked 'li' back. Here is the example: fiddle And here the script: var oldli; $('li').click( function(){ $(oldli).toggleClass('displayNone displayBlock'); $(oldli).css("z-index","1"); $(this).toggleClass('displayBlock displayNone'); $(this).css("z-index","5"); oldli=$(this); } );

Categories : Javascript

C# Finding if a list contains an item duplicated 5 times
stringListName.GroupBy(x => x).Any(x => x.Count() == 5); tested using var stringListName = new string[] { "a", "a", "a", "a", "a", "b" };

Categories : C#

Finding the common item between two list in python
This is not a simple problem for a beginner. A more straightforward approach would use functions like sum and zip with a list comprehension like so: def commons(L1, L2): return sum(el1 == el2 * 1 for el1, el2 in zip(L1, L2)) A more typical but error prone approach taken by beginners is: def commons(L1, L2): count = 0 for i, elem in enumerate(L2): if elem == L1[i]: count += 1 return count I say this is more error prone because there are more parts to get right. Without using enumerate you could do: def commons(L1, L2): count = 0 for i, range(len(L2)): if L1[i] == L2[i]: count += 1 return count but these previous two will work only if len(L2) <= len(L1). See what I mean by more error prone? To fix this you wou

Categories : Python

How to print list item + integer/string using logging in Python
I would do it like this. def funcA(): a = [] a.append(Node(10, 0)) a.append(Node(20, 0)) for i in range(0, len(a)): message = '%s:%s' % (i, a[i].items()) logging.debug(message) Which produces this as output: DEBUG:root:0:[('idx', 10), ('degree', 0)] DEBUG:root:1:[('idx', 20), ('degree', 0)] You could also use join: message = ':'.join([str(i), str(a[i].items())]) Or format: message = '{0}:{1}'.format(str(i), a[i].items()) Whatever is the most clear to you.

Categories : Python

ASP FormView Item Template add empty to dropdown list?
You need to allow the databound items to be appended to your existing list items (including them empty ones) by setting AppendDataBoundItems to true on your DropdownLists. <asp:DropDownList runat="server" ID="yourDDL" AppendDataBoundItems="true">

Categories : C#

WordPress: Add empty list-item to navigation menu
You can add it using jQuery with following code <script> jQuery(document).ready(function(){ jQuery("#menu-primary li").last().before("<li class="stretcher"></li>"); }); </script>

Categories : PHP

Why does Haskell let me return an empty list where a list inside a list is expected?
Because [] is of type [[a]] in this case: it is a list containing exactly 0 alpha lists. In general, the empty list can match any list type because every element (all zero of them) is of the correct type.

Categories : Haskell

WPF How to bind list to itemscontrol with each item being paired to a customcontrol and bound to the ith item in list
The DataContext for each UI item in the ItemsControl will automatically be assigned to the corresponding Data Item in the source Collection. Therefore this is valid and will work: <ItemsControl x:Name ="Signalviewer_Control" ItemsSource="{Binding Source = {StaticResource signal_data}, Path = list_of_signals}"> <ItemsControl.ItemTemplate> <DataTemplate> <wpfExp:SignalViewer Signal="{Binding}"/> </DataTemplate> </ItemsControl.ItemTemplate> </ItemsControl>

Categories : Wpf

Python list manipulation: Add an item to a string element to make it a 2 item list
Modify a[0]: >>> a = ['spam', 'eggs', 100, 1234] >>> a[0] = [a[0], 'Devon'] >>> a [['spam', 'Devon'], 'eggs', 100, 1234] For your updated question: >>> items = ['devon', 'baloney'] >>> a = ['spam', 'eggs', 100, 1234] >>> a[0] = [a[0]] + items >>> a [['spam', 'devon', 'baloney'], 'eggs', 100, 1234] If you're not sure about the position of 'spam' then use a list comprehension: >>> a = ['spam', 'eggs', 100, 1234] >>> [item if item != 'spam' else [item, 'devon'] for item in a] [['spam', 'devon'], 'eggs', 100, 1234]

Categories : Python

Finding drop down list control from a stored procedure in edit item template of gridview in asp.net c#
Instead of doing a FindControl, use an offset index of the column in question and get the first control: (DropDownList)gvLocationArea.Rows[gvLocationArea.EditIndex].Cells[INDEX OF THE DDL].Controls[0]

Categories : C#

Exception: Prelude.last: empty list in Haskell solving 8-queens?
You can fix the immediate problem by checking the length of xs before calling last: safeD l e xs n = if length xs == 0 || last(xs)/=e then ... However, you will then run into another problem because you call safeD(tail xs)(head xs)(tail xs)(1) inside the then part of this branch, and you can reach the then part of this branch when length xs == 0. I strongly recommend learning a little bit about pattern matching (Gentle Intro section, Haskell Report section) and trying to write this entire code snippet without ever calling head, tail, init, last, or length. Instead, use the two patterns [] for matching empty lists and (x:xs) (or similar) for matching lists that start as x and end with xs; if necessary, a call to reverse once in a while would be okay. Good luck, and let us know how you

Categories : Haskell

What exception type to throw if a list/collection is empty or null and cannot be iterated (not a parameter)?
You can create your own exception type for appropriate logic: public class InitializationException : Exception { } and then: throw new InitializationException {Message = "Collection is empty"};

Categories : C#

How to write a overloaded function which can accept List or List in java?
Probably you can take the parameter as List of Object. In the implemention, check the class type of the object passed and have a switch to process different for integer and double Please accept/vote up, if this resolves your query

Categories : Java

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

Finding case sensitive string in a cell from a specific list and return a value from the list
Assuming the following: Sheet 1, column a = Sheet1!A:A Sheet 1, column b = Sheet1!B:B Sheet 2, column a = Sheet2!A:A Sheet 2, column b = Sheet2!B:B You can simply insert an INDEX MATCH into Sheet1!B1 =INDEX(Sheet2!B:B,MATCH(Sheet1!A1,Sheet2!A:A,0))

Categories : Excel

Data structuring - Is there a better alternative to Map>>?
Generally speaking you could split it into classes: class A { Date from; Date until; } class B { List<A> list = ... } class C { List<B> list = ... } of course with meaningful names. So you can use C in your map. You are probably going to have methods on each class level anyway, so later on you don't need to worry about the location of these methods - they just fit nicely into this structure, too.

Categories : Java

How to name a function that convert a list of integer into a list of pair?
Any name which makes some sense will do. In general there's no science to this - just provide appropriately descriptive comments so that others (and you, later) can understand what it does without reading the code. The only time when there is some science to it is when the function is a well known function. For example, if you have a function which rounds a float down to the nearest lesser value with no fractional part, you should probably call it floor. A function which pairs up items should probably be called zip, because again, that's the usual name.

Categories : Python

Create a list of integer elements from list of objects
Use a set: sorted(set().union(first, second)) #returns a sorted list of unique items Demo: >>> first = [0,1,2,3,4,5] >>> second = [4,5,6,7,9] >>> sorted(set(first + second)) [0, 1, 2, 3, 4, 5, 6, 7, 9] If the original order matters: >>> first = [0,1,2,3,4,5] >>> seen = set(first) >>> first += [x for x in second if x not in seen and not seen.add(x)] >>> first [0, 1, 2, 3, 4, 5, 6, 7, 9] For large lists the set approach is going to be efficient as sets provide O(1) lookup, for tiny lists your approach is also okay.

Categories : Python

Why is first text view in list empty when populating the list from SQLite Database?
Try this: Cursor data = database.query("notes", fields, null, null, null, null,null); data.moveToNext(); dataSource = new SimpleCursorAdapter(this, R.layout.highscores, data, fields, new int[] { R.id.first }, 0); Does it works? Remember to add 0 as last parameter to use the non deprecated method.

Categories : Android

Converting an integer list into a string list
You can use List Comprehension: >>> my_list = [1, 2, 3, 4] >>> [str(v) for v in my_list] ['1', '2', '3', '4'] or map(): >>> str_list = map(str, my_list) >>> str_list ['1', '2', '3', '4'] In Python 3, you would need to use - list(map(str, my_list)) For 2nd part, you can use join(): >>> ''.join(str_list) '1234' And please don't name your list list. It shadows the built-in list.

Categories : Python

How to convert List to List?
Nope, there's no other way. But casting is not possible in this case, you need to do use Integer.parseInt(stringValue). List<String> listStrings = ... List<Integer> listIntegers = new ArrayList<Integer>(listStrings.size()); for(String current:listStrings){ listIntegers.add(Integer.parseInt(current)); }

Categories : Java

Why is it not possible to call List not with List even if Integer extends Number?
Because you could e.g. add an instance of a different subclass of Number to List<Number>, e.g., an object of type Double, but obviously you shouldn't be allowed to add them to List<Integer>: public void myMethod(List<Number> list) { list.add(new Double(5.5)); } If you were allowed to call myMethod with an instance of List<Integer> this would result in a type clash when add is called.

Categories : Java

When I access a list on an object it incorrectly returns as empty list
You replace the neighbours parameter with an empty list def __init__(self, (x,y,z), n, radius, neighbours): neighbours = [] # <- HERE self.neighbours = neighbours Remove that line, and you should be able to access the neighbour list.

Categories : Python

why list slices in right-to-left direction returns empty list?
Remember that indexes start at 0: sample_list = [1,2,3,4,5,6,7] # 0 1 2 3 4 5 6 When you do sample_list[-2:2], you're trying to get the second last element to the third element. But you can't just go from negative to positive (unless you add in a negative step). If you wish to obtain a reversed list, then add a step: >>> print sample_list[2:-2][::-1] [5, 4, 3] This is the same problem with your second example. You're trying to go backwards with negative indicies, but you can't... unless... you add in a negative step!: >>> print sample_list[-3:-7:-1] [5, 4, 3, 2]

Categories : Python

Appending an item to a python list in the declaration statement list = [].append(val) is a NoneType
The .append() function alters the list in place and thus always returns None. This is normal and expected behaviour. You do not need to have a return value as the list itself has already been updated. Use the dict.setdefault() method to set a default empty list object: >>> hash = {} >>> hash.setdefault('a', []).append('A') >>> hash {'a': ['A']} You may also be interested in the collections.defaultdict class: >>> from collections import defaultdict >>> hash = defaultdict(list) >>> hash['a'].append('A') >>> hash defaultdict(<type 'list'>, {'a': ['A']}) If you want to return a new list with the extra item added, use concatenation: lst = lst + ['val']

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

Show SQLite data by clicking list item in a list populated by the Database
You need to change focusable mode of your TextView to false update TextView in XML android:focusable="false" lv.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> arg0, View view, int position, long id) { data.moveToPosition(position); Toast.makeText(getApplicationContext(), c.getString(c.getColumnIndex("notes")), Toast.LENGTH_LONG).show(); speakOut(c.getString(c.getColumnIndex(BaseColumns._ID))); } });

Categories : Android

Counting visible list items and then applying class to nth item of that list in jQuery?
Use $.each to iterate over the elements and then apply the logic. var $elems = $('.row-fluid ul.thumbnails li:visible'); $elems.each(function() { var $this = $(this); if($this.hasClass('span3')) { $this.filter(':nth-child(4n + 5)').addClass('span-left'); } else if($this.hasClass('span4')) { $this.filter(':nth-child(3n + 4)').addClass('span-left'); } else if($this.hasClass('span6')) { $this.filter(':nth-child(2n + 3)').addClass('span-left'); } });

Categories : Jquery

Generate unique list item id for all list items in site collection
There is no comparable feature to the documentID service for Items in general out of the box. You would have to build it using Custom code. You can create a custom ID which appends the list GUID and the OOTB item ID which is unique to every item in the site collection.

Categories : Sharepoint

Deserializing List of objects yields empty list
Ok, I've reimplemented your solution in C#, and what makes the difference is the fact that you didn't provide the namespace for TaskRequests in MobileRequest class. To summarize: 1) You mix attributes for DataContractSerializer and XmlSerializer which makes this code hard to manage, I've used only XmlSerializer related attributes. 2) The XML you've provided cannot be the result of serializing the classes you've presented. It contains "MyNameSpace" on TaskReqests field, whereas in your code there are no namespaces for XmlSerializer (only for DataContractSerializer which is not relevant here). 3) The minimal fix of your code to make XML you've given deserialize correctly (see edit below) is: [Serializable] public class MobileRequest { [XmlArray(Namespace="MyNameSpace")] //note the n

Categories : Xml

How to ignore a list mapping when the list is empty but not null?
I wrote this extension, hope it helps! public static void MapListIfNotEmpty<TSource, TMapFrom>(this IMemberConfigurationExpression<TSource> map, Func<TSource, IEnumerable<TMapFrom>> mapFrom) { map.Condition(src => !mapFrom(src).IsNullOrEmpty()); map.MapFrom(mapFrom); } and you can use it like this: Mapper.CreateMap<Model.Event, DataContracts.Event>() .ForMember(des => des.Divisions, e => e.MapListIfNotEmpty(source => source.Geographies));

Categories : C#

Retrieve values from list item when there are varying layouts in the list
Here's an easy way - paste this into each of the xml Views: android:onClick="someFunction" Then inside this someFunction do: public void someFunction(View v){ switch (v.getId()){ case R.id.lblSub: // This layout was clicked, do something about it break; case R.id.lblMain: // This layout was clicked, do something about it break; }

Categories : Android

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#

How to I generate a CSV file from a python list with each list item in a seperate row
Use writerows as follow: myfile = open('/home/graham/Desktop/Experiment/listcsv.csv', 'wb') wr = csv.writer(myfile, quoting=csv.QUOTE_ALL) wr.writerows([path] for path in list_of_paths)

Categories : Python

Infinite loop on list item in unordered list using jQuery
So your update was a good start... I adapted it to include 3 items (jquery selector) rather than 1 and added a fadeOut on the callback of fadeIn to achieve the cycle what you were looking for. After the callback reaches the end of the list, we start over. See below function fadeInSequence($three) { //default to the first three list items if ($three == null) $three = $('.sponsors>li:lt(3)'); //fade in the 3 found $three.fadeIn(2000, function () { //fade out the 3 after fadein and start $(this).fadeOut(2000); }).promise().done(function () { if ($three.last().nextAll(':lt(3)').length) { //Same function, next 3 items fadeInSequence($three.last().nextAll(':lt(3)')); } else { //Same function, from the b

Categories : Jquery

Refreshing the order of an ordered list, after appending a list item
Firstly, note that value is not a valid attribute of li, so your code is invalid. You should use a data attribute for any non-standard attributes you require, the you need to write a sorter function. Try this: $('#addThird').one('click', function() { $('ol').append('<li data-value="3">Third</li>'); sortItems(); }); var sortItems = function() { var $items = $('ol li'); $items.sort(function(a, b) { var keyA = $(a).data('value'); var keyB = $(b).data('value'); return (keyA > keyB) ? 1 : 0; }); $.each($items, function(index, row){ $('ol').append(row); }); } Updated fiddle This sorts by the data-value attribute of the element, but that can be amended as required.

Categories : Javascript

Is it possible to paste a list to a select2 field and match each item in the list?
select2 provides a tokenizer option that lets you pre-process the input. here is a possible implementation for your particular usecase: tokenizer: function(input, selection, callback) { // no comma no need to tokenize if (input.indexOf(',')<0) return; var parts=input.split(","); for (var i=0;i<parts.length;i++) { var part=parts[i]; part=part.trim(); // todo: check for dupes (if part is already in [selection]) // check if the part is valid // todo: you will need a better way of doing this var valid=false; for (var j=0;j<unitIds.length;j++) { if (part===unitIds[j]) { valid=true; break; } } if (valid) callback({id:part,text:p

Categories : Jquery

How to iterate through an unordered list and then select the parent div of the list item
$('.question').filter(function () { return ! $(this).find('input:checked').length; }).addClass('highlight'); Here's the fiddle: http://jsfiddle.net/XTDre/

Categories : Javascript

Kendo UI Web - Drop-down list, different background color on each list item.
There is one easy part and one difficult part. The easy is getting the background the difficult is making it look nice. Easy, define a template for rendering each list item: <script id="template" type="text/kendo-tmpl"> <div style="background-color: #= text #;">#= text #</div> </script> And then define your ComboBox as: $(document).ready(function () { $('#combobox').kendoComboBox({ template : $("#template").html() }); }); but this is likely to do not be as nice as you want since before the <div> from my template there is a <li> introduced by KendoUI and unless you want to start playing with it, you might consider just displaying a color square with the item color. You can do something like: Start defining a CSS for the color

Categories : CSS

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



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