[Tutor] Occurrence of number 2 in a range from 1 to 100

Reuben reuben.dlink at gmail.com
Sun Dec 1 19:02:49 CET 2013


Thanks everyone for all the replies.


On Sun, Dec 1, 2013 at 11:29 PM, Joel Goldstick <joel.goldstick at gmail.com>wrote:

>
>
>
> On Sun, Dec 1, 2013 at 12:53 PM, Mark Lawrence <breamoreboy at yahoo.co.uk>wrote:
>
>> On 01/12/2013 17:40, eryksun wrote:
>>
>>> On Sun, Dec 1, 2013 at 6:14 AM, Steven D'Aprano <steve at pearwood.info>
>>> wrote:
>>>
>>>> On Sun, Dec 01, 2013 at 02:57:33PM +0530, Reuben wrote:
>>>>
>>>>> I mean occurrence of 2 from numbers 1 to 100.  The number could be the
>>>>> first digit or second digit in a two digit number..for e.g. In number
>>>>> 21 it
>>>>> appears as first digit. For number 92 it appears as second digit
>>>>>
>>>>
>>>>
> This way may not be faster, but it may be simpler to understand:
>
> >>> for n in range(100):
> ...   if '2' in str(n):
> ...     print n
> ...
>
>
>>
>> _______________________________________________
>> Tutor maillist  -  Tutor at python.org
>> To unsubscribe or change subscription options:
>> https://mail.python.org/mailman/listinfo/tutor
>>
>
>
>
> --
> Joel Goldstick
> http://joelgoldstick.com
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20131201/942d5238/attachment-0001.html>


More information about the Tutor mailing list