list

Merge contents of multiple lists of custom objects - C#

寵の児 提交于 2021-02-19 08:52:15
问题 I have a class Project as public class Project { public int ProjectId { get; set; } public string ProjectName { get; set; } public string Customer { get; set; } public string Address{ get; set; } } and I have 3 lists List<Project> lst1; List<Project> lst2; List<Project> lst3; lst1 contains Person objects with ProjectId and ProjectName. ProjectId =1, ProjectName = "X", Customer = null, Address = null ProjectId =2, ProjectName = "Y", Customer = null, Address = null lst2 contains Person objects

How can I shuffle a very large list stored in a file in Python?

纵然是瞬间 提交于 2021-02-19 08:11:48
问题 I need to deterministically generate a randomized list containing the numbers from 0 to 2^32-1. This would be the naive (and totally nonfunctional) way of doing it, just so it's clear what I'm wanting. import random numbers = range(2**32) random.seed(0) random.shuffle(numbers) I've tried making the list with numpy.arange() and using pycrypto's random.shuffle() to shuffle it. Making the list ate up about 8gb of ram, then shuffling raised that to around 25gb. I only have 32gb to give. But that

Automapper and inheritance from Collection or List

只谈情不闲聊 提交于 2021-02-19 07:45:07
问题 I'm trying to use AutoMapper (v5.1.1) to map an object which inherits from a List or Collection. The map call does not give me an error but the output is an empty list (of correct type though). I can get a List<DestinationObject> or Collection<DestinationObject> , but it does not seem to work when having a custom class which enherits from List<T> or Collection<T> . I've tried extending the first map definition to include the base class ( List<T> ) but that gives me a StackOverflowException.

rename list of dataframe columns to mimic joined suffixes

青春壹個敷衍的年華 提交于 2021-02-19 07:18:07
问题 I have a list of dataframes: dd <- list() dd$data <- list( ONE = data.frame(inAll = c(1.1,1.2,1.3), inAll_2 = c(1.4,1.5,1.6)), TWO = data.frame(inAll = c(2.1,2.2,2.3), inAll_2 = c(2.4,2.5,2.6)), THREE = data.frame(inAll = c(3.1,3.2,3.3), inAll_2 = c(3.4,3.5,3.6)), FOUR = data.frame(inAll = c(4.1,4.2,4.3), inAll_2 = c(4.4,4.5,4.6)), FIVE = data.frame(inAll = c(5.1,5.2,5.3), inAll_2 = c(5.4,5.5,5.6)), SIX = data.frame(inAll = c(6.1,6.2,6.3), inAll_2 = c(6.4,6.5,6.6)) ) And then reduce those

How to print a list with a delay between each item in HTML

徘徊边缘 提交于 2021-02-19 07:03:22
问题 <html> <body> //Id for each item <p id=1></p> <p id=2></p> <p id=3></p> <script> for(i = 0; i < 3; i++) { window.setTimeout(press, 1000); //Should use For loop variable to fetch and print specific element's Id function press() { document.getElementById(i).innerHTML = i; } } </script> </body> </html> I'm a bit of a noob to all of this. Most of these commands I got from w3schools and I'm just trying to piece everything together bit by bit. 回答1: You can pass an argument through to the timeout

Recasting nested list of any depth

杀马特。学长 韩版系。学妹 提交于 2021-02-19 06:06:54
问题 Assume this simplified example: L <- list() L$Foo <- list() L$Foo$Bar <- list() L$Foo$Bar$VAR <- TRUE L$Lorem <- list() L$Lorem$Ipsum <- list() L$Lorem$Ipsum$Dolor <- list() L$Lorem$Ipsum$Dolor$VAR <- TRUE I will then melt this list with reshape2::melt(L) . That will output the following: value L3 L2 L4 L1 1 TRUE VAR Bar <NA> Foo 2 TRUE Dolor Ipsum VAR Lorem After some operations on certain cells in the value column, I'm then looking to recast this melted list into the exact same nested list

All possible (monogamous) pairings of two lists (of boys and girls)

回眸只為那壹抹淺笑 提交于 2021-02-19 03:36:10
问题 I have these two lists: boys = [1,2,3] girls = [1,2,3] How would you build all possible (monogamous) pairings [boy, girl] ? With only 3 of both boys and girls , I think this is the list of all the possible pairings: [ [[1,1], [2,2], [3,3]], [[1,1], [2,3], [3,2]], [[1,2], [2,1], [3,3]], [[1,2], [2,3], [3,2]], [[1,3], [2,1], [3,2]], [[1,3], [2,2], [3,1]] ] How would you do it in general (in above format)? This is what I've been able to come up ... pairs = list(itertools.product(boys, girls))

Scala pattern matching: How to match on an element inside a list?

末鹿安然 提交于 2021-02-18 22:28:20
问题 Is it possible to rewrite the following code using Scala pattern matching? val ls: List[String] = ??? // some list of strings val res = if (ls.contains("foo")) FOO else if (ls.contains("bar")) BAR else SOMETHING_ELSE 回答1: You could implement this using a function like def onContains[T](xs: Seq[String], actionMappings: (String, T)*): Option[T] = { actionMappings collectFirst { case (str, v) if xs contains str => v } } And use it like this: val x = onContains(items, "foo" -> FOO, "bar" -> BAR )

Obtaining length of list as a value in dictionary in Python 2.7

倖福魔咒の 提交于 2021-02-18 22:28:09
问题 I have two lists and dictionary as follows: >>> var1=[1,2,3,4] >>> var2=[5,6,7] >>> dict={1:var1,2:var2} I want to find the size of the mutable element from my dictionary i.e. the length of the value for a key. After looking up the help('dict') , I could only find the function to return number of keys i.e. dict.__len__() . I tried the Java method(hoping that it could work) i.e. len(dict.items()[0]) but it evaluated to 2 . I intend to find this: Length of value for first key: 4 Length of value

Scala pattern matching: How to match on an element inside a list?

孤人 提交于 2021-02-18 22:27:06
问题 Is it possible to rewrite the following code using Scala pattern matching? val ls: List[String] = ??? // some list of strings val res = if (ls.contains("foo")) FOO else if (ls.contains("bar")) BAR else SOMETHING_ELSE 回答1: You could implement this using a function like def onContains[T](xs: Seq[String], actionMappings: (String, T)*): Option[T] = { actionMappings collectFirst { case (str, v) if xs contains str => v } } And use it like this: val x = onContains(items, "foo" -> FOO, "bar" -> BAR )