Re: What's with all of the Case Solution and Test Bank nonsense posts?

2017-07-10 Thread Wanderer
On Sunday, July 9, 2017 at 8:59:45 PM UTC-4, timetowalk wrote:
> On Sunday, July 9, 2017 at 8:05:59 PM UTC-4, Michael Torrie wrote:
> > On 07/09/2017 05:39 PM, timetowal...@gmail.com wrote:
> > > I use https://groups.google.com/forum/#!forum/comp.lang.python to look 
> > > over message posts.
> > > 
> > > What's with all of the Case Solution and Test Bank nonsense posts?
> > > Is is possible to have these posts filtered out?
> > 
> > I'm sure Google could filter them if it chose.  Behind the group,
> > though, is the Usenet newsgroup, which is unmoderated and decentralized,
> > and you can't filter there. That's why most people read Usenet with a
> > good news reader app that can apply filtering and kill rules for you.
> > 
> > And of course the mailing list side of things does filter out messages
> > and kills certain points.  Probably your cleanest experience will come
> > through the mailing list.  Use an email folder and a filter to place all
> > list serv emails in a folder and you'll get a good experience. You can
> > even do this with Gmail.  My gmail account has all my list serv messages
> > sorted out on the Gmail server into labels, and I have a special rule to
> > killfile messages from some sources.
> 
> I will need to read about filtering messages locally.
> Can the admin simply ban the user?

I wrote this Python script to locally ban (block, kill file, plonk, whatever 
you want to call it) authors and posted it here a little while back. This way I 
don't have to turn on javascript to look at the google groups list.

https://groups.google.com/forum/?_escaped_fragment_=msg/comp.lang.python/EKRYfj06OeA/RnpM6stNAwAJ#!msg/comp.lang.python/EKRYfj06OeA/RnpM6stNAwAJ
-- 
https://mail.python.org/mailman/listinfo/python-list


AUCPR of individual features using Random Forest (Error: unhashable Type)

2017-07-10 Thread mscs15059


I have a data set of 19 features (v1---v19) and one class label (c1) , I can 
eaily get the precision recall value of all variables with the class label, but 
I want the AUCPR of individual features with the class label The data is in 
this form

V1   V2   V3V4  V5  V6  V7  V8  V9  V10 V11 V12 V13 V14 V15 V16 V17 
V18   V19   C1
4182418241821   2   0   0   0   4   1   1   0   5   0   1   1   24  
4.4654  28.18955043 1
11396   3798.6  38253   1   0   1   0   0   3   3   1   0   1   1   3   5   
4.452   11.90765492 0
60416   5034.66 5393.5  12  1   0   0   0   0   12  12  3   6   1   4   12  2   
4.4711  35.11543135 0
34580   494052547   1   4   0   2   0   10  12  8   0   1   1   10  45  
4.4689  32.44228433 1
86674333.5  4333.5  2   1   0   1   0   0   2   2   1   0   1   0   2   1   
4.4659  28.79708384 0
4011401140111   1   30  0   0   0   2   2   1   8   1   0   2   1   
4.4634  25.75941677 0
691347  5083.43 5300136 2   0   0   0   9   44  44  12  0   1   12  44  32  
4.4693  32.92831106 1
So far I have done this

from collections import defaultdict
from sklearn.cross_validation import train_test_split
from sklearn.ensemble import RandomForestClassifier
import pandas as pd
import numpy as np
from sklearn.metrics import average_precision_score

mydata = pd.read_csv("TEST_2.csv")
y = mydata["C1"]  #provided your csv has header row, and the label column is 
named "Label"

##select all but the last column as data
X = mydata.ix[:,:-1]
X=X.iloc[:,:]
names = X.iloc[:,:].columns.tolist()
# -- Gridsearched parameters
model_rf = RandomForestClassifier(n_estimators=500,
 class_weight="auto",
 criterion='gini',
 bootstrap=True,
 max_features=10,
 min_samples_split=1,
 min_samples_leaf=6,
 max_depth=3,
 n_jobs=-1)
scores = defaultdict(list)

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=.5,
random_state=0)
# -- Fit the model (could be cross-validated)



for i in range(X_train.shape[1]):
X_t = X_test.copy()
rf = model_rf.fit(X_train[:,i], y_train)
scores[names[i]] = average_precision_score(y_test, rf.predict(X_t[:,i))




print("Features sorted by their score:")
print(sorted([(round(np.mean(score), 4), feat) for
  feat, score in scores.items()], reverse=True))
It gives the error unhashable type

The output should be something like that

V1: 0. 82
V2: 0.74
:
:
V19: 0.55
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: AUCPR of individual features using Random Forest (Error: unhashable Type)

2017-07-10 Thread Steve D'Aprano
Hi mscs15059 and welcome!

(If you'd rather be known with a more friendly name, you can either sign your
messages at the end, or configure your email or news software to show your
name.)

On Mon, 10 Jul 2017 09:47 pm, mscs15...@itu.edu.pk wrote:

> I have a data set of 19 features (v1---v19) and one class label (c1) , I can
> eaily get the precision recall value of all variables with the class label,
> but I want the AUCPR of individual features with the class label The data is
> in this form

Unfortunately while we're Python experts here, we're not necessarily pandas
experts. I have no idea what AUCPR means.


[...]
> It gives the error unhashable type

What gives the error?

Please COPY and PASTE (don't retype from memory) the full error, starting with
the line that begins with "Traceback", to the end. 

That way we can see the exact error you are getting, and more importantly, which
line of code is producing it. Then we can start making suggestions for how to
fix the problem.




-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What's with all of the Case Solution and Test Bank nonsense posts?

2017-07-10 Thread Larry Martell
On Sun, Jul 9, 2017 at 10:37 PM,   wrote:
> On Sunday, July 9, 2017 at 8:53:18 PM UTC-5, Steve D'Aprano wrote:
>> On Mon, 10 Jul 2017 11:41 am, voteswithf...@gmail.com wrote:
>>
>> > On Sunday, July 9, 2017 at 7:59:45 PM UTC-5, timetowalk wrote:
>>
>> >> I will need to read about filtering messages locally.
>> >> Can the admin simply ban the user?
>> >
>> > There is no admin, you idiot. This is Usenet!
>>
>> That's unnecessarily rude,
>
> I only meant it as friendly banter. But you're right. Next time I should use 
> a less offensive word like twit.

If you really wanted to be less rude you would have said 'upper class twit'
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What's with all of the Case Solution and Test Bank nonsense posts?

2017-07-10 Thread Jon Ribbens
On 2017-07-10, John Black  wrote:
> While you're at it, throw these rules in and the group will appear very 
> clean and on topic.
>
> Subject contains "PEDOFILO"
> Or
> Subject contains "MAI"
> Or
> Subject contains "SEGRETO"
[snip >100 lines of rules]

Or just "subject does not contain any lower-case letters".
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What's with all of the Case Solution and Test Bank nonsense posts?

2017-07-10 Thread Jon Ribbens
On 2017-07-09, Michael Torrie  wrote:
> I'm sure Google could filter them if it chose.  Behind the group,
> though, is the Usenet newsgroup, which is unmoderated and decentralized,
> and you can't filter there.

... unless the group were changed to be moderated, which it really
ought to be, being a mirror of a list.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What's with all of the Case Solution and Test Bank nonsense posts?

2017-07-10 Thread Michael Torrie
On 07/09/2017 09:29 PM, Chris Roy-Smith wrote:
> can you get a newsreader to work with a https news service?

No.  A newsreader works with NNTP protocol. Some Usenet servers offer
SSL support over port 443, but that's certainly not https. I've never
heard of an https news service before.  Unless you're talking about a
web-based newsgroups reader, such as google groups.  In the latter case
you're completely at the mercy of whatever features Google sees fit to
throw your way.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What's with all of the Case Solution and Test Bank nonsense posts?

2017-07-10 Thread John Black
In article , 
jon+use...@unequivocal.eu says...
> 
> On 2017-07-10, John Black  wrote:
> > While you're at it, throw these rules in and the group will appear very 
> > clean and on topic.
> >
> > Subject contains "PEDOFILO"
> > Or
> > Subject contains "MAI"
> > Or
> > Subject contains "SEGRETO"
> [snip >100 lines of rules]
> 
> Or just "subject does not contain any lower-case letters".

That is probably ok, but I was worried some legit posts would get caught 
in that.

John Black
-- 
https://mail.python.org/mailman/listinfo/python-list


ezdxf type of spline

2017-07-10 Thread amka1791
Hi,

Can someone says please to me which kind are the splines of the ezdxf python 
module ? Is it bezier curves ?

Thanks,

dylan

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Test 0 and false since false is 0

2017-07-10 Thread Grant Edwards
On 2017-07-09, Paul D. DeRocco  wrote:
>> From: Sayth Renshaw
>> 
>> I have been reading this solution 
>> > >>> after = sorted(before, key=lambda x: x == 0 and type(x) == int)
>> 
>> it is really good, however I don't understand it enough to 
>> reimplement something like that myself yet.
>> 
>> Though I can that lambda tests for 0 that is equal to an int 
>> why does sorted put them to the end?
>
> Because the expression "x == 0 and type(x) == int" has a value of either
> False or True, and it sorts all the False values before the True values,
> leaving the order within those sets unchanged.
>
> That said, "x is 0" is even simpler.

And wrong.

Two equivalent integer objects _might_ be the same object, but that's
not guaranteed.  It's an _implementation_detail_ of CPython that small
integers are cached:

  >>> x =  0
  >>> x is 0
  True

But larger integers aren't:

  >>> a =  123412341234
  >>> a is 123412341234
  False

The first example could have returned False and been correct.

-- 
Grant Edwards   grant.b.edwardsYow! TONY RANDALL!  Is YOUR
  at   life a PATIO of FUN??
  gmail.com

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What's with all of the Case Solution and Test Bank nonsense posts?

2017-07-10 Thread Jon Ribbens
On 2017-07-10, John Black  wrote:
> In article , 
> jon+use...@unequivocal.eu says...
>> On 2017-07-10, John Black  wrote:
>> > While you're at it, throw these rules in and the group will appear very 
>> > clean and on topic.
>> >
>> > Subject contains "PEDOFILO"
>> > Or
>> > Subject contains "MAI"
>> > Or
>> > Subject contains "SEGRETO"
>> [snip >100 lines of rules]
>> 
>> Or just "subject does not contain any lower-case letters".
>
> That is probably ok, but I was worried some legit posts would get caught 
> in that.

I don't think that rule would block too many reasonable posts. On the
other hand, I also block everything from Google Groups, and, as of
recently, everything from netfront.net, so I don't actually worry too
much about false positives in this group, given it contains so much
trash.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What's with all of the Case Solution and Test Bank nonsense posts?

2017-07-10 Thread pyotr filipivich
timetowal...@gmail.com on Sun, 9 Jul 2017 16:39:44 -0700 (PDT) typed
in comp.lang.python  the following:
>I use https://groups.google.com/forum/#!forum/comp.lang.python to look over 
>message posts.
>
>What's with all of the Case Solution and Test Bank nonsense posts?
>Is is possible to have these posts filtered out?

Kill files are your friend.

marking all from 
author: allcasesoluti...@gmail.com
"Read" works for me.  you could delete them.

Unfortunately, how to get Google Groups to behave properly is
another story entire.
-- 
pyotr filipivich
Next month's Panel: Graft - Boon or blessing?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What's with all of the Case Solution and Test Bank nonsense posts?

2017-07-10 Thread Paul Rubin
Michael Torrie  writes:
>> can you get a newsreader to work with a https news service?
> No.  A newsreader works with NNTP protocol.

Traditionally NNTP over SSL was done on port 563.  Some feeds now also
provide it on 443 to get around client-side firewall hassles.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What's with all of the Case Solution and Test Bank nonsense posts?

2017-07-10 Thread Michael Torrie
On 07/10/2017 11:05 AM, Paul Rubin wrote:
> Michael Torrie  writes:
>>> can you get a newsreader to work with a https news service?
>> No.  A newsreader works with NNTP protocol.
> 
> Traditionally NNTP over SSL was done on port 563.  Some feeds now also
> provide it on 443 to get around client-side firewall hassles.

Yes but that's not via https.

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What's with all of the Case Solution and Test Bank nonsense posts?

2017-07-10 Thread Chris Angelico
On Tue, Jul 11, 2017 at 4:12 AM, Michael Torrie  wrote:
> On 07/10/2017 11:05 AM, Paul Rubin wrote:
>> Michael Torrie  writes:
 can you get a newsreader to work with a https news service?
>>> No.  A newsreader works with NNTP protocol.
>>
>> Traditionally NNTP over SSL was done on port 563.  Some feeds now also
>> provide it on 443 to get around client-side firewall hassles.
>
> Yes but that's not via https.

What's the meaning of "https news service" then? If it's netnews, it's
NNTP, not HTTP. If it just happens to be a web app that carries
information from a newsgroup, then that's not a news service, it's a
web forum, and there's no such thing as a generic web forum API.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What's with all of the Case Solution and Test Bank nonsense posts?

2017-07-10 Thread Pete Forman
Chris Angelico  writes:

> On Tue, Jul 11, 2017 at 4:12 AM, Michael Torrie  wrote:
>> On 07/10/2017 11:05 AM, Paul Rubin wrote:
>>> Michael Torrie  writes:
> can you get a newsreader to work with a https news service?
 No.  A newsreader works with NNTP protocol.
>>>
>>> Traditionally NNTP over SSL was done on port 563. Some feeds now
>>> also provide it on 443 to get around client-side firewall hassles.
>>
>> Yes but that's not via https.
>
> What's the meaning of "https news service" then? If it's netnews, it's
> NNTP, not HTTP. If it just happens to be a web app that carries
> information from a newsgroup, then that's not a news service, it's a
> web forum, and there's no such thing as a generic web forum API.

RFC 4642 (updated by RFC 8143) describes the use of TLS with NNTP. It
enhances the connection between NNTP client and server, primarily with
encryption but optionally with other benefits.

Of course it does nothing to improve the content of Usenet.

-- 
Pete Forman
-- 
https://mail.python.org/mailman/listinfo/python-list


Compiling Python 3.6.1 on macOS 10.12.5

2017-07-10 Thread Nigel Palmer
Hi

I am trying to compile Python 3.6.1  on macOS 10.12.5 with xcode 8.8.3 using 
the instructions at 
https://docs.python.org/devguide/setup.html#build-dependencies but I am getting 
the error

./python.exe -E -S -m sysconfig --generate-posix-vars ;\
if test $? -ne 0 ; then \
echo "generate-posix-vars failed" ; \
rm -f ./pybuilddir.txt ; \
exit 1 ; \
fi
/bin/sh: line 1: 96973 Killed: 9   ./python.exe -E -S -m sysconfig 
--generate-posix-vars
generate-posix-vars failed
make: *** [pybuilddir.txt] Error 1

When I manually run that command using dbll I get:

lldb ./python.exe -- -E -S -m sysconfig --generate-posix-vars
(lldb) target create "./python.exe"
Current executable set to './python.exe' (x86_64).
(lldb) settings set -- target.run-args  "-E" "-S" "-m" "sysconfig" 
"--generate-posix-vars"
(lldb) r
Process 96978 launched: './python.exe' (x86_64)
Could not find platform dependent libraries 
Consider setting $PYTHONHOME to [:]
Process 96978 exited with status = 0 (0x)
(lldb)


The commands I ran to configure and build python are:
brew install openssl xz
CPPFLAGS="-I$(brew --prefix openssl)/include" LDFLAGS="-L$(brew --prefix 
openssl)/lib" ./configure --prefix=`pwd`/../build
make

Any ideas on what I am doing wrong?

Many Thanks
Nigel
-- 
https://mail.python.org/mailman/listinfo/python-list


ANN: A new version (0.4.1) of python-gnupg has been released.

2017-07-10 Thread Vinay Sajip via Python-list
A new version of the Python module which wraps GnuPG has been released.

What Changed?
=
This is an enhancement and bug-fix release, and all users are encouraged to 
upgrade.
See the project website [1] for more information.

Brief summary:

* Updated message handling logic to no longer raise exceptions when a message 
isn't
  recognised. Thanks to Daniel Kahn Gillmor for the patch.
* Always use always use --fixed-list-mode, --batch and --with-colons. Thanks to 
Daniel
  Kahn Gillmor for the patch.
* Improved scan_keys() handling on GnuPG >= 2.1. Thanks to Daniel Kahn Gillmor 
for the
  patch.
* Improved test behaviour with GnuPG >= 2.1. Failures when deleting test 
directory trees
  are now ignored. Thanks to Daniel Kahn Gillmor for the patch.
* Added close_file keyword argument to verify_file to allow the file closing to 
be made
  optional. Current behaviour is maintained - close_file=False can be passed to 
skip
  closing the file being verified.
* Added the extra_args keyword parameter to allow custom arguments to be passed 
to the
  gpg executable.
* Instances of the GPG class now have an additional on_data attribute, which 
defaults to
  None. It can be set to a callable which will be called with a single argument 
- a binary
  chunk of data received from the gpg executable. The callable can do whatever 
it likes
  with the chunks passed to it - e.g. write them to a separate stream. The 
callable should
  not raise any exceptions (unless it wants the current operation to fail).

This release [2] has been signed with my code signing key:

Vinay Sajip (CODE SIGNING KEY) 
Fingerprint: CA74 9061 914E AC13 8E66 EADB 9147 B477 339A 9B86

What Does It Do?

The gnupg module allows Python programs to make use of the
functionality provided by the Gnu Privacy Guard (abbreviated GPG or
GnuPG). Using this module, Python programs can encrypt and decrypt
data, digitally sign documents and verify digital signatures, manage
(generate, list and delete) encryption keys, using proven Public Key
Infrastructure (PKI) encryption technology based on OpenPGP.

This module is expected to be used with Python versions >= 2.4, as it
makes use of the subprocess module which appeared in that version of
Python. This module is a newer version derived from earlier work by
Andrew Kuchling, Richard Jones and Steve Traugott.

A test suite using unittest is included with the source distribution.

Simple usage:

>>> import gnupg
>>> gpg = gnupg.GPG(gnupghome='/path/to/keyring/directory')
>>> gpg.list_keys()

[{
...
'fingerprint': 'F819EE7705497D73E3CCEE65197D5DAC68F1AAB2',
'keyid': '197D5DAC68F1AAB2',
'length': '1024',
'type': 'pub',
'uids': ['', 'Gary Gross (A test user) ']},
{
...
'fingerprint': '37F24DD4B918CC264D4F31D60C5FEFA7A921FC4A',
'keyid': '0C5FEFA7A921FC4A',
'length': '1024',
...
'uids': ['', 'Danny Davis (A test user) ']}]
>>> encrypted = gpg.encrypt("Hello, world!", ['0C5FEFA7A921FC4A'])
>>> str(encrypted)

'-BEGIN PGP MESSAGE-\nVersion: GnuPG v1.4.9 (GNU/Linux)\n
\nhQIOA/6NHMDTXUwcEAf
.
-END PGP MESSAGE-\n'
>>> decrypted = gpg.decrypt(str(encrypted), passphrase='secret')
>>> str(decrypted)

'Hello, world!'
>>> signed = gpg.sign("Goodbye, world!", passphrase='secret')
>>> verified = gpg.verify(str(signed))
>>> print "Verified" if verified else "Not verified"

'Verified'

As always, your feedback is most welcome (especially bug reports [3],
patches and suggestions for improvement, or any other points via the
mailing list/discussion group [4]).

Please refer to the documentation [5] for more information.

Enjoy!

Cheers

Vinay Sajip
Red Dove Consultants Ltd.

[1] https://bitbucket.org/vinay.sajip/python-gnupg
[2] https://pypi.python.org/pypi/python-gnupg/0.4.1
[3] https://bitbucket.org/vinay.sajip/python-gnupg/issues
[4] https://groups.google.com/forum/#!forum/python-gnupg
[5] https://gnupg.readthedocs.io/en/latest/ 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Compiling Python 3.6.1 on macOS 10.12.5

2017-07-10 Thread INADA Naoki
>  Killed: 9

It looks like not segmentation fault.
Maybe, RAM shortage?
INADA Naoki  


On Mon, Jul 10, 2017 at 10:24 PM, Nigel Palmer  wrote:
> Hi
>
> I am trying to compile Python 3.6.1  on macOS 10.12.5 with xcode 8.8.3 using 
> the instructions at 
> https://docs.python.org/devguide/setup.html#build-dependencies but I am 
> getting the error
>
> ./python.exe -E -S -m sysconfig --generate-posix-vars ;\
> if test $? -ne 0 ; then \
> echo "generate-posix-vars failed" ; \
> rm -f ./pybuilddir.txt ; \
> exit 1 ; \
> fi
> /bin/sh: line 1: 96973 Killed: 9   ./python.exe -E -S -m 
> sysconfig --generate-posix-vars
> generate-posix-vars failed
> make: *** [pybuilddir.txt] Error 1
>
> When I manually run that command using dbll I get:
>
> lldb ./python.exe -- -E -S -m sysconfig --generate-posix-vars
> (lldb) target create "./python.exe"
> Current executable set to './python.exe' (x86_64).
> (lldb) settings set -- target.run-args  "-E" "-S" "-m" "sysconfig" 
> "--generate-posix-vars"
> (lldb) r
> Process 96978 launched: './python.exe' (x86_64)
> Could not find platform dependent libraries 
> Consider setting $PYTHONHOME to [:]
> Process 96978 exited with status = 0 (0x)
> (lldb)
>
>
> The commands I ran to configure and build python are:
> brew install openssl xz
> CPPFLAGS="-I$(brew --prefix openssl)/include" LDFLAGS="-L$(brew --prefix 
> openssl)/lib" ./configure --prefix=`pwd`/../build
> make
>
> Any ideas on what I am doing wrong?
>
> Many Thanks
> Nigel
> --
> https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What's with all of the Case Solution and Test Bank nonsense posts?

2017-07-10 Thread Michael Torrie
On 07/10/2017 02:06 PM, Pete Forman wrote:
>> What's the meaning of "https news service" then? If it's netnews, it's
>> NNTP, not HTTP. If it just happens to be a web app that carries
>> information from a newsgroup, then that's not a news service, it's a
>> web forum, and there's no such thing as a generic web forum API.
> 
> RFC 4642 (updated by RFC 8143) describes the use of TLS with NNTP. It
> enhances the connection between NNTP client and server, primarily with
> encryption but optionally with other benefits.

Again, that is not HTTPS. Don't confuse port number with protocol!

As Chris says, Google Groups is essentially a web forum that happens to
mirror Usenet content.  It's not a news service itself (no NNTP), not an
NNTP server.  So if GG is causing users problems, the solution is to
ditch it and use something better, like a standalone NNTP client and a
real Usenet server.  Or python-list via email.

I wish there was a decent (free) API that everyone used for web forums
that would let me use a decent, threaded news reader to browse forums.
I once wrote a forum scraper using BeautifulSoup that downloaded posts,
along with graphics and made them into MIME messages served over NNTP
(using Twisted) to my NNTP client.  So much information is lost in web
forums (there's no threading in web forums) that it didn't work out that
well.
-- 
https://mail.python.org/mailman/listinfo/python-list


Write this accumuator in a functional style

2017-07-10 Thread Steven D'Aprano
I have a colleague who is allergic to mutating data structures. Yeah, I 
know, he needs to just HTFU but I thought I'd humour him.

Suppose I have an iterator that yields named tuples:

Parrot(colour='blue', species='Norwegian', status='tired and shagged out')

and I want to collect them by colour:

accumulator = {'blue': [], 'green': [], 'red': []}
for parrot in parrots:
accumulator[parrot.colour].append(parrot)


That's pretty compact and understandable, but it require mutating a bunch 
of pre-allocated lists inside an accumulator. Can we re-write this in a 
functional style?

The obvious answer is "put it inside a function, then pretend it works by 
magic" but my colleague's reply to that is "Yes, but I'll know that its 
actually doing mutation inside the function".


Help me humour my colleague.



-- 
Steve
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Write this accumuator in a functional style

2017-07-10 Thread Gregory Ewing

Steven D'Aprano wrote:

Help me humour my colleague.


class Parrot:

def __init__(self, color, species, status):
self.color = color
self.species = species
self.status = status

def __repr__(self):
return "%s/%s/%s" % (self.species, self.color, self.status)

def parrot_generator():
yield Parrot(color='blue', species='Norwegian',
status='tired and shagged out')
yield Parrot(color='green', species='Portugese', status='perky')
yield Parrot(color='red', species='Hawaiian', status='laid back')
yield Parrot(color='blue', species='Norwegian', status='dead')
yield Parrot(color='green', species='Italian', status='excited')
yield Parrot(color='blue', species='French', status='tres bon')

def parrots_of_color(parrots, color):
return [p for p in parrots if p.color == color]

def accumulated_parrots(parrot_source):
parrots = list(parrot_source)
return {color: parrots_of_color(parrots, color)
for color in set(p.color for p in parrots)}

print(accumulated_parrots(parrot_generator()))
--
https://mail.python.org/mailman/listinfo/python-list


Re: Write this accumuator in a functional style

2017-07-10 Thread Wolfgang Maier

On 07/11/2017 08:11 AM, Steven D'Aprano wrote:

I have a colleague who is allergic to mutating data structures. Yeah, I
know, he needs to just HTFU but I thought I'd humour him.

Suppose I have an iterator that yields named tuples:

Parrot(colour='blue', species='Norwegian', status='tired and shagged out')

and I want to collect them by colour:

accumulator = {'blue': [], 'green': [], 'red': []}
for parrot in parrots:
 accumulator[parrot.colour].append(parrot)


That's pretty compact and understandable, but it require mutating a bunch
of pre-allocated lists inside an accumulator. Can we re-write this in a
functional style?

The obvious answer is "put it inside a function, then pretend it works by
magic" but my colleague's reply to that is "Yes, but I'll know that its
actually doing mutation inside the function".


Help me humour my colleague.





Hmm, isn't this just asking for itertools.groupby on the parrots sorted 
by colour?


--
https://mail.python.org/mailman/listinfo/python-list


Re: Compiling Python 3.6.1 on macOS 10.12.5

2017-07-10 Thread Chris Warrick
Why are you trying to compile Python manually? You should use Homebrew to
install Python in 99% of cases. (The package is python3)

-- 
Chris Warrick 
-- 
https://mail.python.org/mailman/listinfo/python-list