collect

Extracting data from Web

柔情痞子 提交于 2019-12-08 01:51:01
问题 One really newbie question. I'm working on a small python script for my home use, that will collect data of a specific air ticket. I want to extract the data from skyscanner (using BeautifulSoap and urllib). Example: http://www.skyscanner.net/flights/lond/rome/120922/120929/airfares-from-london-to-rome-in-september-2012.html And I'm interested in all the data that are stored in this kind of element, specially the price: http://shrani.si/f/1w/An/1caIzEzT/capture.png Because they are not

How to make Groovy / Grails return a List of objects instead of a List of Lists of objects?

大兔子大兔子 提交于 2019-12-07 03:37:19
问题 I have a class like this: class Foo { static hasMany = [bars: Bar] } When I write: Foo.getAll() I get a list of Foo objects like this: [ Foo1, Foo2, Foo3 ] When I write: Foo.getAll().bars I get a list of lists of Bar object like this: [ [ Bar1, Bar2 ], [ Bar2, Bar3 ], [ Bar1, Bar4 ] ] But what I want is a unique list of Bar objects like this: [ Bar1, Bar2, Bar3, Bar4 ] My end goal is to have a unique list of ids of the Bar object in the list above, like this: [ 1, 2, 3, 4 ] I have tried

I want my memory back! How can I truly dispose a control?

孤街醉人 提交于 2019-12-07 00:22:57
问题 I have an application I am making that creates a large number of windows controls (buttons and labels etc). They are all being made dynamically through functions. The problem I'm having is, when I remove the controls and dispose them, they are not removed from memory. void loadALoadOfStuff() { while(tabControlToClear.Controls.Count > 0) tabControlToClear.Controls[0].Dispose(); //I even put in: GC.Collect(); GC.WaitForPendingFinalizers(); foreach(String pagename in globalList)

Linq Map! or Collect!

醉酒当歌 提交于 2019-12-06 16:41:54
问题 What is the Linq equivalent to the map! or collect! method in Ruby? a = [ "a", "b", "c", "d" ] a.collect! {|x| x + "!" } a #=> [ "a!", "b!", "c!", "d!" ] I could do this by iterating over the collection with a foreach, but I was wondering if there was a more elegant Linq solution. 回答1: Map = Select var x = new string[] { "a", "b", "c", "d"}.Select(s => s+"!"); 回答2: The higher-order function map is best represented in Enumerable.Select which is an extension method in System.Linq . In case you

Scala: how to traverse stream/iterator collecting results into several different collections

为君一笑 提交于 2019-12-06 11:00:58
问题 I'm going through log file that is too big to fit into memory and collecting 2 type of expressions, what is better functional alternative to my iterative snippet below? def streamData(file: File, errorPat: Regex, loginPat: Regex): List[(String, String)]={ val lines : Iterator[String] = io.Source.fromFile(file).getLines() val logins: mutable.Map[String, String] = new mutable.HashMap[String, String]() val errors: mutable.ListBuffer[(String, String)] = mutable.ListBuffer.empty for (line <- lines

Extracting data from Web

久未见 提交于 2019-12-06 04:32:21
One really newbie question. I'm working on a small python script for my home use, that will collect data of a specific air ticket. I want to extract the data from skyscanner (using BeautifulSoap and urllib). Example: http://www.skyscanner.net/flights/lond/rome/120922/120929/airfares-from-london-to-rome-in-september-2012.html And I'm interested in all the data that are stored in this kind of element, specially the price: http://shrani.si/f/1w/An/1caIzEzT/capture.png Because they are not located in the HTML, can I extract them? zenpoy I believe the problem is that these values are rendered

How to make Groovy / Grails return a List of objects instead of a List of Lists of objects?

假装没事ソ 提交于 2019-12-05 07:20:21
I have a class like this: class Foo { static hasMany = [bars: Bar] } When I write: Foo.getAll() I get a list of Foo objects like this: [ Foo1, Foo2, Foo3 ] When I write: Foo.getAll().bars I get a list of lists of Bar object like this: [ [ Bar1, Bar2 ], [ Bar2, Bar3 ], [ Bar1, Bar4 ] ] But what I want is a unique list of Bar objects like this: [ Bar1, Bar2, Bar3, Bar4 ] My end goal is to have a unique list of ids of the Bar object in the list above, like this: [ 1, 2, 3, 4 ] I have tried variations of the collect method and I have also tried the spread operator but I'm not having any luck. For

Linq Map! or Collect!

冷暖自知 提交于 2019-12-04 23:44:31
What is the Linq equivalent to the map! or collect! method in Ruby? a = [ "a", "b", "c", "d" ] a.collect! {|x| x + "!" } a #=> [ "a!", "b!", "c!", "d!" ] I could do this by iterating over the collection with a foreach, but I was wondering if there was a more elegant Linq solution. Map = Select var x = new string[] { "a", "b", "c", "d"}.Select(s => s+"!"); The higher-order function map is best represented in Enumerable.Select which is an extension method in System.Linq . In case you are curious the other higher-order functions break out like this: reduce -> Enumerable.Aggregate filter ->

How to use collect call in Java 8?

坚强是说给别人听的谎言 提交于 2019-12-04 15:33:46
问题 Lets say we have this boring piece of code that we all had to use: ArrayList<Long> ids = new ArrayList<Long>(); for (MyObj obj : myList){ ids.add(obj.getId()); } After switching to Java 8, my IDE is telling me that I can replace this code with collect call , and it auto-generates: ArrayList<Long> ids = myList.stream().map(MyObj::getId).collect(Collectors.toList()); However its giving me this error: collect(java.util.stream.Collector) in Steam cannot be applied to: (java.util.stream.Collector,

Scala: how to traverse stream/iterator collecting results into several different collections

∥☆過路亽.° 提交于 2019-12-04 15:10:25
I'm going through log file that is too big to fit into memory and collecting 2 type of expressions, what is better functional alternative to my iterative snippet below? def streamData(file: File, errorPat: Regex, loginPat: Regex): List[(String, String)]={ val lines : Iterator[String] = io.Source.fromFile(file).getLines() val logins: mutable.Map[String, String] = new mutable.HashMap[String, String]() val errors: mutable.ListBuffer[(String, String)] = mutable.ListBuffer.empty for (line <- lines){ line match { case errorPat(date,ip)=> errors.append((ip,date)) case loginPat(date,user,ip,id) =