Re: Python help needed

2019-08-07 Thread MRAB

On 2019-08-07 21:36, Kuyateh Yankz wrote:
  
#trying to write a function that takes a list value as an argument and returns a string with all the items separated by a comma and a space, with and inserted before the last item. For example, passing the previous spam list to the function would return 'apples, bananas, tofu, and cats'. But your function should be able to work with any list value passed to it.


def myList(aParameter): #defined
 finalList = []
 for i in range(len(aParameter)-1): #targeting the last item in the list
   finalList.append('and '+ aParameter[-1]) #Removes the last item in the 
list, append the last item with THE and put it back, then put it into the FINAL 
LIST FUNCTION.
 return finalList
spam = ['apples', 'bananas', 'tofu', 'cats']
print(myList(spam))

#Got up to this point, still couldn't get rid of the '' around the items and 
the []. I tried (','.join()) but could not get there.
#Am I on the wrong path or there's a quick fix here?
https://pastebin.com/JCXisAuz

There's a nice way of doing it using str.join. However, you do need to 
special-case when there's only 1 item.


Start with a list:

>>> spam = ['apples', 'bananas', 'tofu', 'cats']

The last item will be have an 'and', so let's remove that for the moment:

>>> spam[ : -1]
['apples', 'bananas', 'tofu']

Join these items together with ', ':

>>> ', '.join(spam[ : -1])
'apples, bananas, tofu'

Now for the last item:

>>> ', '.join(spam[ : -1]) + ' and ' + spam[-1]
'apples, bananas, tofu and cats'

For the special case, when len(spam) == 1, just return spam[0].

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


Python help needed

2019-08-07 Thread Kuyateh Yankz
 
#trying to write a function that takes a list value as an argument and returns 
a string with all the items separated by a comma and a space, with and inserted 
before the last item. For example, passing the previous spam list to the 
function would return 'apples, bananas, tofu, and cats'. But your function 
should be able to work with any list value passed to it.

def myList(aParameter): #defined 
finalList = [] 
for i in range(len(aParameter)-1): #targeting the last item in the list
  finalList.append('and '+ aParameter[-1]) #Removes the last item in the 
list, append the last item with THE and put it back, then put it into the FINAL 
LIST FUNCTION.
return finalList
spam = ['apples', 'bananas', 'tofu', 'cats']
print(myList(spam))

#Got up to this point, still couldn't get rid of the '' around the items and 
the []. I tried (','.join()) but could not get there.
#Am I on the wrong path or there's a quick fix here?
https://pastebin.com/JCXisAuz
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Trouble installing python

2019-08-07 Thread Sanford Lefkowitz
I have basically the same question. have you found an answer yet?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: class definition question

2019-08-07 Thread Terry Reedy

On 8/7/2019 3:26 PM, Manfred Lotz wrote:

On Wed, 07 Aug 2019 14:39:00 -0400
Dennis Lee Bieber  wrote:


On Wed, 7 Aug 2019 20:11:15 +0200, Manfred Lotz 
declaimed the following:


Hi there,
More often I see something like this:

class Myclass:
...


but sometimes I see

class Myclass(object):
...


Question: which way is preferable?


It's historical...

Python v1.x had a form of classes.

Python v2.x introduced "new-style" classes. "New-style"
classes /had/ to inherit from "object", as they had different
behavior from "v1.x old-style" classes which were still supported (it
would have broken too many programs). Old-style were then deprecated,
and one should have used new-style for new code.

Python v3.x unified (removed old-style behavior differences)
and all classes inherit from "object" whether one specifies object or
not.




Thanks a lot for the explanations.

As a Python newbie (with no Pythons legacies) I only deal with Python 3.
So, I will happily ignore 'object'.


That is preferred, because it is extra work to write and read, with no 
benefit, and because myclass(object) can be seen as implying that the 
code once ran or is still meant to be compatible with Python 2.



--
Terry Jan Reedy

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


Re: class definition question

2019-08-07 Thread Manfred Lotz
On Wed, 07 Aug 2019 14:39:00 -0400
Dennis Lee Bieber  wrote:

> On Wed, 7 Aug 2019 20:11:15 +0200, Manfred Lotz 
> declaimed the following:
> 
> >Hi there,
> >More often I see something like this:
> >
> >class Myclass:
> >...
> >
> >
> >but sometimes I see
> >
> >class Myclass(object):
> >...
> >
> >
> >Question: which way is preferable?  
> 
>   It's historical...
> 
>   Python v1.x had a form of classes.
> 
>   Python v2.x introduced "new-style" classes. "New-style"
> classes /had/ to inherit from "object", as they had different
> behavior from "v1.x old-style" classes which were still supported (it
> would have broken too many programs). Old-style were then deprecated,
> and one should have used new-style for new code.
> 
>   Python v3.x unified (removed old-style behavior differences)
> and all classes inherit from "object" whether one specifies object or
> not.
> 
> 

Thanks a lot for the explanations.

As a Python newbie (with no Pythons legacies) I only deal with Python 3.
So, I will happily ignore 'object'.

-- 
Manfred


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


class definition question

2019-08-07 Thread Manfred Lotz
Hi there,
More often I see something like this:

class Myclass:
...


but sometimes I see

class Myclass(object):
...


Question: which way is preferable?

-- 
Manfred

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


Re: [poliastro-dev] ANN: poliastro 0.13.0 released ????

2019-08-07 Thread Oleg Broytman
Can I ask you to remove python-announce from the list of addresses?
It's not a mailing list for discussions.

On Wed, Aug 07, 2019 at 06:16:43PM +0200, Samuel Leli??vre 
 wrote:
> Le mar. 6 ao??t 2019 ?? 08:33, Samuel Dupree  a ??crit 
> :
> 
> > Juan Luis Cano,
> >
> > When will poliastro ver. 0.13.0 become available from Anaconda? At the
> > time of this note, only ver. 0.12.0 is available.
> >
> > Lastly what is the recommended procedure to update poliastro from vers.
> > 0.12.0 to 0.13.0?
> >
> > Sam Dupree
> >
> 
> A pull request was automatically created by a bot:
> 
> https://github.com/conda-forge/poliastro-feedstock/pull/29
> 
> and Juan Luis merged it yesterday, so that the new version is
> available since yesterday, see the version badge on the README at
> 
> https://github.com/conda-forge/poliastro-feedstock
> 
> Clicking on that badge sends to:
> 
> https://anaconda.org/conda-forge/poliastro
> 
> which has the installation instructions.
> 
> Use `conda upgrade` instead of `conda install` if you want to upgrade.
> --
> Python-announce-list mailing list -- python-announce-l...@python.org
> To unsubscribe send an email to python-announce-list-le...@python.org
> https://mail.python.org/mailman3/lists/python-announce-list.python.org/
> 
> Support the Python Software Foundation:
> http://www.python.org/psf/donations/

Oleg.
-- 
Oleg Broytmanhttps://phdru.name/p...@phdru.name
   Programmers don't die, they just GOSUB without RETURN.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: For the code to generate `zen of python'.

2019-08-07 Thread Thomas Jollans
On 07/08/2019 15.11, Hongyi Zhao wrote:
> Hi here,
>
> I noticed that the `zen of python' is generated by the following code:
>
> d = {}
> for c in (65, 97):
> for i in range(26):
> d[chr(i+c)] = chr((i+13) % 26 + c)
>
> print("".join([d.get(c, c) for c in s]))
>
>
> But the above code is not so easy for me to figure out.  Could someone 
> please give me some explanations on it?
>
> Regards


This code
[https://github.com/python/cpython/blob/master/Lib/this.py#L23] doesn’t
‘generate’ the Zen of Python, really. It just decrypts it. The Zen of
Python is hidden just above those lines.

Abj gur dhrfgvba vf: pna lbh svther bhg gur plcure?

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


Re: For the code to generate `zen of python'.

2019-08-07 Thread Paul Moore
It's basically a decryption of the string s in the same module, that's
encoded using the ROT13 algorithm -
https://en.wikipedia.org/wiki/ROT13. This isn't meant to be secure,
it's basically a little bit of fun obfuscating the actual text.

The code creates a dictionary mapping encoded characters to their
decoded equivalents. Decoding is done by adding 13 to the ASCII value
of the letter (wrapping round from 25 back to 0). That's about it,
really.

Paul

On Wed, 7 Aug 2019 at 14:17, Hongyi Zhao  wrote:
>
> Hi here,
>
> I noticed that the `zen of python' is generated by the following code:
>
> d = {}
> for c in (65, 97):
> for i in range(26):
> d[chr(i+c)] = chr((i+13) % 26 + c)
>
> print("".join([d.get(c, c) for c in s]))
>
>
> But the above code is not so easy for me to figure out.  Could someone
> please give me some explanations on it?
>
> Regards
> --
> .: Hongyi Zhao [ hongyi.zhao AT gmail.com ] Free as in Freedom :.
> --
> https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


For the code to generate `zen of python'.

2019-08-07 Thread Hongyi Zhao
Hi here,

I noticed that the `zen of python' is generated by the following code:

d = {}
for c in (65, 97):
for i in range(26):
d[chr(i+c)] = chr((i+13) % 26 + c)

print("".join([d.get(c, c) for c in s]))


But the above code is not so easy for me to figure out.  Could someone 
please give me some explanations on it?

Regards
-- 
.: Hongyi Zhao [ hongyi.zhao AT gmail.com ] Free as in Freedom :.
-- 
https://mail.python.org/mailman/listinfo/python-list