w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Dictionary to List> where the Value in KeyValuePair is MyClass.ToString()
Not tested/compiled, but something like that should work: dict.Select(kvp => new KeyValuePair<string, string>(kvp.Key, kvp.Value.ToString())).ToList() if the syntax is not 100% spot on, I hope you got the idea.

Categories : C#

How to get all properties with an specific name and create a List>
SyncJobs_Result job = (SyncJobs_Result)entity.Entity; var properties = typeof(SyncJobs_Result) .GetProperties(BindingFlags.Static | BindingFlags.Public) .Where(p => p.Name.Contains("Role") && p.PropertyType == typeof(string)) .Select(p => new KeyValuePair<string, string>(p.Name, p.GetValue(job, null) as string)) .ToList(); Writing without Visual Studio so there may be a syntax error or two, but hopefully this will point you in the right direction.

Categories : C#

How do I remove an entry from List> based on just the key?
Use List.RemoveAll. You can pass in a predicate which checks the key value. Example: myList.RemoveAll(kvp => kvp.Key == "@index");

Categories : C#

Nicer Syntax for List>?
You can accept just strings as parameters and then dynamically fill a dictionary, like this. public void MyMethod(params string[] properties) { var pairs = new Dictionary<string, string>(); for(int i = 0; i < properties.length - 1; i += 2) { pairs.Add(properties[i], properties[i + 1]); } } MyMethod("Name", "Jack", "City", "New York", "Gender", "Male");

Categories : C#

Can List.Distinct() apply to the list type of List>?
That's because List<T> has no Equals and GetHashCode implemented, so standard reference comparison is being performed. And it returns false, because you have two separated lists. You can write your own IEqualityComparer<List<string>> implementation and provide it as Distinct method parameter. Within the comparer you can use Enumerable.SequenceEqual) method to check if lists has the same content.

Categories : C#

Java Collection: what to convert Collection> to ArrayList> or List>?
You can use the appropriate constructor: List<List<String>> yourList = new ArrayList<>(yourCollection); The order of the elements in the list is the order of the iterator of the collection.

Categories : Java

Can't retrieve data from list
Instead of List<KeyValuePair>, use Dictionary<string, SelectList> and then you can access it like : array[key] = value; You can use Dictionary like: Dictionary<String, SelectList> dictionary= new Dictionary<String, SelectList>(); dictionary.Add("theKey", "FIND THIS!"); Console.WriteLine(dictionary["theKey"]);

Categories : C#

How to add List containing item of type List ,int,string into another List
Use the power of LINQ: var B = A.GroupBy(x => new { x.Name, x.EngineType }) .Select(g => new Car { Name = g.Key.Name, EngineType = g.Key.EngineType, Months = g.SelectMany(x => x.Months.Select((y,i) => new { i, y = int.Parse(y) })) .GroupBy(x => x.i) .OrderBy(g2 => g2.Key) .Select(g2 => g2.Sum(x => x.y).ToString()).ToList() }).ToList();

Categories : C#

Adding a string to a List inside of a List>
You are correct, with the error, you need to understand that the List<List<string>> will take a List<string> and NOT A String. Try something like this; List<string> listOfString = new List<string>; for (int i = 0; i <= filesToRead.Count; i++) { using (var reader = new StreamReader(filesToRead[i])) { string line; while ((line = reader.ReadLine()) != null) { listOfString.add(line); } } } Then, _toLoad.add(listOfStrings);

Categories : C#

Is there a way to print out an object from a script as it would appear in the REPL? (e.g. myList: List[String] = List(Hello there, World!)
The Scala equivalent of this would be the getClass method (from Java) on java.lang.Object. For instance: scala> 1.getClass res0: Class[Int] = int scala> Nil.getClass res1: Class[_ <: scala.collection.immutable.Nil.type] = class scala.collection.immutable.Nil$ scala> "hello".getClass res2: Class[_ <: String] = class java.lang.String

Categories : Scala

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

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

Python encoding: list to string having special characters and numbers in the list
If you can specify the strings in your list as unicode, like: [u"Círculo", 23] [u"Triángulo", 25, 19, u"dos"] then this should work: u', '.join(unicode(x) for x in list_of_ints) Assuming you are running Python 2.

Categories : Python

Using C# LINQ to concat a filtered List to List
If names is empty, what you're meant to do is this: var names = businessNames.Select(item => item.Name).ToList(); Another option is to use the List<T>'s ConvertAll method, like so: var names = buisnessNames.ConvertAll(item => item.Name); However, if it may be not empty, you'd need to use an if statement too: var names = new List<string>(); //some code if (names.Any()) names.AddRange(/*your selected method*/); else names = //your selected method;

Categories : C#

Getting unique values from a list of objects with a List as a property
If I understand, you want a list of all of the unique certifications among all of the employees. This would be a job for SelectMany: var uniqueCerts = empList.SelectMany(e => e.Certifications).Distinct().ToList();

Categories : C#

concatenate list by user input (string) and displaying the List
You need an append list1 += [b] instead of assignment list1 = [b] And in Python in this case its better to use for in. Also raw_input would return a string, you do not need to convert it for a in range(3): b = raw_input("cmd : ") list1 += [b] Or even better to use list comprehension as there is an overhead for appending a list. list1 = [raw_input("cmd : ") for _ in range(3)]

Categories : Python

How to parse String List into List using Gson
Your getGenericClass() won't work, you need to retrieve the class of T. You can provide it : Class<T> type; public Class<T> getType() { return this.type; } or get it at runtime (unsafe, you can find many post on this subjet I think) public Class<T> getType() { return (Class<T>) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0]; } Then to build the list token you can use this code : static TypeToken<?> getGenToken(final Class<?> raw, final Class<?> gen) throws Exception { Constructor<ParameterizedTypeImpl> constr = ParameterizedTypeImpl.class.getDeclaredConstructor(Class.class, Type[].class, Type.class); constr.setAccessible(true); ParameterizedTypeImpl paramType = cons

Categories : List

passing a List that is a class generates error, List that is string does not
It's pretty obvious what's going on here, everything you need to know is in your error message. You have 2 different declarations for the Rooms class, one in your RoomViewController and the other in your TableSource and appear to be leaking them across your classes. You need to make sure you are passing the expected type into the TableSource class. To elaborate further, your TableSource constructor looks like: public TableSource(List<CupuleAdmin.TableSource.Rooms> table) { } And you are trying to pass: List<CupuleAdmin.RoomViewController.Rooms> allrooms = new List<...>(); table.Source = new TableSource(allrooms);

Categories : C#

iterating list of array-list and assigning each list to single dynamically created div in jsp
Try this, <c:forEach var="user" items="${userList}" varStatus="count"> <div id="col${count}"> <c:out value="${user.name}"/> </div> </c:forEach>

Categories : Java

In a responsive site design, how do i put a list below other list that contains a sub-list without overlap the main lists
Pretty simple : remove the fixed height of your li.menulinks, add a "header" (green rounded rectangle with 35px height) div as first child of the li and...you're set ! Look at this fiddle : http://jsfiddle.net/32pga/ <div class="sitemap"> <div class="row-fluid"> <ul> <li class="menulinks"> <div class="menulinks-header"></div> <ul> <li class="submenulinks"> <div>Test 1</div> </li> <li class="submenulinks"> <div>Test 2</div> </li> <li class="submenulinks"> <div>Test

Categories : HTML

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

Python List of Strings created from a list of one string
Just split the first element on ', ': >>> ['dogs, cats'][0].split(', ') ['dogs', 'cats'] >>> >>> ['x, y, z'][0].split(', ') ['x', 'y', 'z'] If you can have multiple comma separated string in your list, then you can use list comprehension: >>> li = ['x, y, z', 'dogs, cats'] >>> >>> li2 = [elem.split(', ') for elem in li] >>> [v for val in li2 for v in val] ['x', 'y', 'z', 'dogs', 'cats'] Or using sum() over list comprehension: >>> li = ['x, y, z', 'dogs, cats'] >>> >>> sum([elem.split(', ') for elem in li], []) ['x', 'y', 'z', 'dogs', 'cats'] And finally itertools: >>> list(itertools.chain.from_iterable(elem.split(', ') for elem in li)) ['x', 'y', 'z', 'dogs', 'cats']

Categories : Python

Find if a string is not part of a list of list in Python
Something like: data = [['abc-kr', 0, 4, -0.031], ['kkg-kg', 0, 6, -0.03], ['art-m', 1, 20, 0.036], ['abc-kg', 0, 4, -0.023]] new_data = {el[0].partition('-')[0]:el for el in data}.values()

Categories : Python

Back-convert a list (formatted as a string) into a list
Use ast.literal_eval to convert a string to a python object(safely): >>> from ast import literal_eval >>> strs = "[{'T': 13472}, {'A': 13472}, {'C': 9866, 'T': 3606}, {'G': 13472}, {'G': 13472}, {'A': 221, 'C': 26, 'T': 12845, 'G': 380}, {'T': 13472}, {'A': 13472}, {'C': 546, 'T': 12926}, {'C': 13472}, {'A': 13472}, {'C': 10674, 'T': 2798}, {'C': 13472}, {'A': 13472}, {'C': 554, 'T': 12918}, {'C': 13472}, {'A': 13472}]" >>> literal_eval(strs) [{'T': 13472}, {'A': 13472}, {'C': 9866, 'T': 3606}, {'G': 13472}, {'G': 13472}, {'A': 221, 'C': 26, 'T': 12845, 'G': 380}, {'T': 13472}, {'A': 13472}, {'C': 546, 'T': 12926}, {'C': 13472}, {'A': 13472}, {'C': 10674, 'T': 2798}, {'C': 13472}, {'A': 13472}, {'C': 554, 'T': 12918}, {'C': 13472}, {'A': 13472}]

Categories : Python

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

How to modify the style in list(ordered list and unordered list) in HTML?
Here you go. WORKING DEMO The HTML: <ul style="list-style-type:decimal;"> <li>First</li> <li>Second</li> <li>Third</li> </ul> The CSS: li{ position: relative; } li:before{ position: absolute; left: -13px; content: ')'; background:white;} Hope this helps.

Categories : HTML

How to search from a list inside a dictionary>
Wouldn't this be done with a linq statement? Sure. It won't be efficient, but it's pretty simple: var input = "456"; var matchingKeys = dictionary.Where(kvp => kvp.Value.Contains(input)) .Select(kvp => kvp.Key); If you want it to be efficient as well, you should store the reverse mapping too, and update both together.

Categories : C#

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

Filling a DataGridView with a List>()
If you had a class with the properties defined in it, and then have a List<customClass> then it would be simple. Plus it defines the column names for you. Not sure if that is feasible in your situation. public class foo { public string foo1 {get;set;} public string foo2 {get;set;} } public Form1() { InitializeComponent(); var foo = new foo() ; foo.foo1 = "some"; foo.foo2 = "text"; List<foo> _foo = new List<foo>(); _foo.Add(foo); dgv.DataSource = _foo; }

Categories : C#

Comparing list of string with the list of boolean
Not sure how you control the visibility using bool. But a converter with a parameter may help. public class ViewModel { public ViewModel() { Columns = new List<string> { "Width", "Height" }; } public List<string> Columns { get; private set; } } public class CustomizedConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { List<string> list = value as List<string>; string keyword = parameter as string; return list.Contains(keyword); } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)

Categories : C#

How to add a string to list inside other list on python 2.7
list.append() does not return anything. It appends the item in place, without actually returning the new list. Because it does not return anything, Python defaults this to None (that is why None is printed) You can simply do: >>> l[1].append('new_str')

Categories : Python

Binding List> to ItemsControl
You've got a few things that need to be changed. You'll only need one ItemsControl. It's the outer ItemsControl that is used to iterate through the items in the List<>. In this case, you've got a List<List<string>>. Each item in the RowsData is a List<string>. Since you're not interested in looping through all items of the inner List<string>, you'll remove the inner ItemsControl and adjust the Binding. The syntax for binding to an indexer is to specify the index in C# notation: [#]. There's not a property of the List<string> that you can use to access the indexed value (remember that all bindings must be to properties or use a converter). In this case, there's special property path syntax that does exactly what you need. Making those changes: <

Categories : Json

C# - How to write a List> to CSV file?
CSV format by itself does not intend to be formatted with rows with variable columns length. CSV (Comma separated values) is just "table like" format, so if you want to follow its convention, you have to first define all possible columns and fill rows one-by-one, so several cells on several rows will remain empty. If this is not what you want, just choose your custom format.

Categories : C#

Convert List of numbers to List of String
toString is not a function that takes an argument, it is a method of the global object, but methods are not bound by default in JS. a.map(function (x) { return x.toString(); }) will do what you want, as will a.map(String) since the String constructor when called as a function coerces its argument to a string.

Categories : Javascript

How do I convert List[String] to List[ServerAddress]?
You could do this: val serverAddrs = seeds.map((s) => new ServerAddress(s)) Edit: Here is a more concise way: val serverAddrs = seeds.map(new ServerAddress(_))

Categories : Scala

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

What kind of List is List list = Database.getAllData();?
You don't have to know; that's the point. The interface is what matters to you, not the implementation. You can't know without looking at the source of that method. But even if you do, it's immaterial to your client. All you call are List methods.

Categories : Java

In python, what happens, will the length of a list decrease if I add part of the list to another list?
The string "hi" will be split into chars and assigned to example when you do example+=python[0] So example in this case will contain ['h','i']. Also, the list python will not lose an element.

Categories : Python

Unmarshall xml list of objects to java list without class list
You could use JAXB with StAX to do the following: import java.util.*; import javax.xml.bind.*; import javax.xml.stream.*; import javax.xml.transform.stream.StreamSource; public class Demo { public static void main(String[] args) throws Exception { JAXBContext jc = JAXBContext.newInstance(User.class); XMLInputFactory xif = XMLInputFactory.newFactory(); StreamSource xml = new StreamSource("src/forum17047306/input.xml"); XMLStreamReader xsr = xif.createXMLStreamReader(xml); List<User> users = new ArrayList<User>(); Unmarshaller unmarshaller = jc.createUnmarshaller(); while(xsr.getEventType() != XMLStreamReader.END_DOCUMENT) { if(xsr.isStartElement() && "User".equals(xsr.getLocalName())) {

Categories : Java



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