Re: list comprehension

2019-02-21 Thread Joan Pujol Tarrés
tion#Parallels_in_programming_languages
>> >>
>> >> This is the Python notation:
>> >>
>> >> Example 1: {l for l in L}
>> >> Example 2: {(k, x) for k in K for x in X if P(x)}
>> >>
>> >> This is another example in Python:
>> >>
>> >> s = {v for v in 'ABCDABCD' if v not in 'CB'}
>> >>
>> >> https://en.wikipedia.org/wiki/List_comprehension#Similar_constructs
>> >>
>> >> I have been playing with the code below. Nevertheless, I am unsure on
>> >> how to use the code to define a set.
>> >>
>> >> Cheers!
>> >>
>> >> <--- Code
>> >> #!/usr/bin/env perl6
>> >>
>> >> my @L = 1 .. 10;
>> >> my @K = 1 .. 10;
>> >> my @X = 5 .. 15;
>> >>
>> >> say "Example 1:";
>> >> for @L -> $l {
>> >>   print "$l " if $l ∈ @L;
>> >> }
>> >>
>> >> say "\nExample 2:";
>> >> for @K -> $k { for @X -> $x {
>> >> print "($k, $x), " if ($k ∈ @K and $x ∈ @X and $x < 8);
>> >> }}
>> >> <---
>> >>
>> >> --
>> >> (≧∇≦) Mimosinnet (Linux User: #463211)
>>
>> --
>> (≧∇≦) Mimosinnet (Linux User: #463211)
>>
>> (≧∇≦) Ningún Lugar
>> 
>> ★ Activisme Cultural per a la Transformació Social
>>
>> (≧∇≦) Fractalitats en Investigació Crítica
>> 
>> * Investigació Crítica per a la Transformació Social
>> * http://psicologiasocial.uab.es/fic
>>

-- 

Joan Pujol Tarrés
Departament de Psicologia Social
Facultat de Psicologia, Universitat Autònoma de Barcelona
Despatx: B5-036 (Passadís Departament Psicologia Social)
Edifici B, 08193 Bellaterra (Barcelona), Fax: +34 935812001

http://orcid.org/-0002-0462-3278
https://portalrecerca.csuc.cat/orcid/-0002-0462-3278


Re: Using HashBags

2018-04-08 Thread Joan Pujol

El Saturday, 07 de April del 2018 a les 16:47, Siavash va escriure:

Don't know if there is a better way, but assuming you don't have 
control

over the data, you can do this:

my Bag $docents = @rows.map(*.pairup).Bag;


This is what I was looking for! I did not came across the 'pairup' 
method. 

Many thanks! 

Cheers! 


On 2018-04-07 10:10:52 GMT, mimosinnet wrote:

Hi all,

I do not seem to be able to get this done with the Bag or BagHash
type:

---
dd @rows;


Output: Array @rows = [["JF", 1], ["JF", 2], ["MM", 2], ["MPu", 2],
["MM", 2], ["FE", 2], ["FV", 2], ["MPu", 2], ["JP", 2], ["JP", 2],
["FV", 2], ["FV", 2], ["JF", 2], ["MM", 2], ["MPu", 2], ["MM", 2],
["FE", 2], ["FV", 2], ["MPu", 2], ["JP", 2], ["JP", 2], ["JF", 4]]


my %docents;
for @rows -> @row {
%docents{ @row[0] } += @row[1];
}

dd %docents;


Output: Hash %docents = {:FE(4), :FV(8), :JF(9), :JP(8), :MM(8),
:MPu(8)}


---

As I understand it, this would better be achieved with the Bag or
BagHash type. What would be the easy way?

Thanks!




--

Joan Pujol Tarrés
Departament de Psicologia Social
Facultat de Psicologia, Universitat Autònoma de Barcelona
Despatx: B5-036 (Passadís Departament Psicologia Social)
Edifici B, 08193 Bellaterra (Barcelona), Fax: +34 935812001

http://orcid.org/-0002-0462-3278
https://portalrecerca.csuc.cat/orcid/-0002-0462-327


Re: Sorting Multidimentional Arrays

2016-10-01 Thread Joan Pujol

El Saturday, 01 de October del 2016 a les 20:44, Moritz Lenz va escriure:


On 01.10.2016 19:57, mimosinnet wrote:

@opposite = @opposite.sort({@$^a[3]});


For the record, you can simplify this a bit:

@opposite = @opposite.sort(*[3]);


Waw! It works! Many thanks! 

I am still puzzled by the asterisk. I will have to dig more into the 
documentation :D :)


Cheers! 


for @opposite -> $line { say $line; }
---

I have adapted this from:
http://www.wellho.net/resources/ex.php?item=p600/mapper

I wanted to ask about the syntax, buy I have understood it while
writing the message ;) :D


I've had the same experience a few times :-)

Cheers,
Moritz

--
Moritz Lenz
https://deploybook.com/ -- https://perlgeek.de/ -- https://perl6.org/


--
Joan Pujol Tarrés
Departament de Psicologia Social
Facultat de Psicologia, Universitat Autònoma de Barcelona
Despatx: B5-036 (Passadís Departament Psicologia Social)
Edifici B, 08193 Bellaterra (Barcelona), Fax: +34 935812001
http://psicologiasocial.uab.es/ca/user/43
http://psicologiasocial.uab.es/fic
http://orcid.org/-0002-0462-3278
--
signature.asc -> http://www.thelounge.net/signature.asc.what.htm
--
()  campaña lazo ascii  |  por favor, enviar correo ascii
/\  www.asciiribbon.org |  por favor, enviar adjuntos en formato libre