[Tutor] skip/slice more than every second?
Alan Gauld
alan.gauld at btinternet.com
Tue Sep 29 12:30:04 CEST 2015
On 29/09/15 04:33, Sebastian Cheung via Tutor wrote:
>> On 29 Sep 2015, at 04:16, questions anon <questions.anon at gmail.com> wrote:
>>
>> a = [1,2,3,4,5,6,7,8,9,10,11,12,13,14]
>>
>> how can I show the first then skip three and show the next and so on?
> print range(1,15,4)
>
> ans: [1, 5, 9,13]
>
While this gives the output that the OP asked for, its
what's known as a coincidental solution. It is just
a coincidence that the data generated by range()
matches the sample data provided. If the OP had provided
a random set of data or used a different type
(eg characters) then this would not help.
--
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
More information about the Tutor
mailing list