Re: [Tutor] Iteration issues

2018-05-12 Thread Peter Otten
Neil Cerutti wrote:

> punctuation_removal_table = str.maketrans({c: None for c in
> string.punctuation})

Alternative spellings:

>>> from string import punctuation
>>> (str.maketrans({c: None for c in punctuation})
...  == str.maketrans(dict.fromkeys(punctuation))
...  == str.maketrans("", "", punctuation))
True


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Question about a python finction

2018-05-12 Thread peter
range does not work the same for 2.7 and my 3.6.5. Seems they have 
changed the nature of range. It is a built in listed along with lists 
and tuples



list(range(10))

[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

>>> tuple(range(10))
(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)

seems they have changed range for python3.6.5 I do not know about the 
earlier python3 versions.  range(10) will not work with python3.6.5


check out https://docs.python.org/3.6/library/stdtypes.html#typesseq

On 05/11/2018 12:58 PM, David Rock wrote:

On May 9, 2018, at 07:14, kevin hulshof  wrote:

Hello,

Is there a function that allows you to grab the numbers between two numbers?

Eg. If you input the numbers 1 and 4
To make a list like this [1,2,3,4]

One option is range

range(1,5)


range(1,5)

[1, 2, 3, 4]

https://docs.python.org/2/library/functions.html#range

—
David Rock
da...@graniteweb.com




___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Question about a python finction

2018-05-12 Thread Alan Gauld via Tutor
On 12/05/18 06:40, peter wrote:
> range does not work the same for 2.7 and my 3.6.5. Seems they have 
> changed the nature of range. It is a built in listed along with lists 
> and tuples

You are correct in that it has changed slightly and now returns
a range object. but you can convert it to a list(or tuple) easily

> 
 list(range(10))
> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
> 
>  >>> tuple(range(10))
> (0, 1, 2, 3, 4, 5, 6, 7, 8, 9)

Just as you have done here.

And if you don;t mneed the explicot list you can use it in a for loop
etc exactly as before:

for n in range(10):...

> ...range(10) will not work with python3.6.5

Yes it will, it just returns a slightly different value that
you must explicitly convert to a list if needed.


-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor