Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #41619
| Path | csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <python-python-list@m.gmane.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.002 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'win32': 0.03; 'syntax': 0.03; 'puts': 0.07; 'python': 0.09; 'lawrence': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'sep': 0.09; 'cases': 0.15; 'help?': 0.16; 'really?': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'syntaxerror:': 0.16; 'wed,': 0.16; 'wrote:': 0.17; '>>>': 0.18; 'define': 0.20; 'bit': 0.21; '"",': 0.22; 'example': 0.23; 'script': 0.24; 'header:In-Reply-To:1': 0.25; 'header:User- Agent:1': 0.26; 'skip:" 20': 0.26; 'header:X-Complaints-To:1': 0.28; 'skip:( 20': 0.28; '+0100,': 0.29; 'decimal': 0.29; 'subject:numbers': 0.29; 'url:python': 0.32; 'file': 0.32; 'from:addr:yahoo.co.uk': 0.32; 'print': 0.32; 'to:addr:python- list': 0.33; 'list': 0.35; 'so,': 0.35; 'doing': 0.35; 'received:org': 0.36; 'but': 0.36; 'url:org': 0.36; 'url:library': 0.36; 'subject:: ': 0.38; 'mark': 0.38; 'things': 0.38; 'url:docs': 0.38; 'instead': 0.39; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'further': 0.61; 'more': 0.63; 'hours': 0.66; '2013': 0.84; 'case?': 0.84; 'otten': 0.84; 'url:string': 0.84; 'ana': 0.91; 'subject:Lists': 0.93 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| To | python-list@python.org |
| From | Mark Lawrence <breamoreboy@yahoo.co.uk> |
| Subject | Re: Lists and Decimal numbers |
| Date | Wed, 20 Mar 2013 19:53:53 +0000 |
| References | <9d8e4386-e6f5-4303-8a6a-be2a16e45ce7@googlegroups.com> <mailman.3567.1363794723.2939.python-list@python.org> <t_n2t.145340$927.82085@fx23.fr7> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8; format=flowed |
| Content-Transfer-Encoding | 8bit |
| X-Gmane-NNTP-Posting-Host | host-92-18-20-125.as13285.net |
| User-Agent | Mozilla/5.0 (Windows NT 6.0; rv:17.0) Gecko/20130307 Thunderbird/17.0.4 |
| In-Reply-To | <t_n2t.145340$927.82085@fx23.fr7> |
| X-Antivirus | avast! (VPS 130311-2, 11/03/2013), Outbound message |
| X-Antivirus-Status | Clean |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.3575.1363809193.2939.python-list@python.org> (permalink) |
| Lines | 68 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1363809193 news.xs4all.nl 6868 [2001:888:2000:d::a6]:42561 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:41619 |
Show key headers only | View raw
On 20/03/2013 19:20, Alister wrote:
> On Wed, 20 Mar 2013 16:52:00 +0100, Peter Otten wrote:
>
>> Ana Dionísio wrote:
>>
>>> So, I have this script that puts in a list every minute in 24 hours
>>>
>>> hour=[]
>>> i=0 t=-(1.0/60.0)
>>> while i<24*60:
>>> i = i+1 t = t+(1.0/60.0)
>>> hour.append([t])
>>
>> In many cases you can write
>>
>> for i in range(...):
>> ...
>>
>> instead of incrementing manually.
>>
>>> When it is doing the cicle it can have all the decimal numbers, but I
>>> need to print the result with only 4 decimal numbers
>>>
>>> How can I define the number of decimal numbers I want to print in this
>>> case? For example with 4 decimal numbers, it would print:
>>>
>>> 0.0000 0.0167 0.0333 ...
>>>
>>> Can you help?
>>
>>
>>>>> for i in range(24*60):
>> ... print "{:.4f}".format(i/60.0)
>> ...
>> 0.0000 0.0167 0.0333 0.0500 [...]
>> 23.9500 23.9667 23.9833
>>>>>
>>>>>
>> See also
>>
>> <http://docs.python.org/2/library/string.html#format-specification-mini-
> language>
>
>
> and a list comprehension would streamline things further
>
> t=[round(x*1.0/60),4 for x in range(1440)] #compatible with V2.7 & V3.0)
>
Really?
c:\Users\Mark\Python>python
Python 3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012, 10:55:48) [MSC v.1600 32
bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> t=[round(x*1.0/60),4 for x in range(1440)] #compatible with V2.7 &
V3.0)
File "<stdin>", line 1
t=[round(x*1.0/60),4 for x in range(1440)] #compatible with V2.7 &
V3.0)
^
SyntaxError: invalid syntax
--
Cheers.
Mark Lawrence
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Lists and Decimal numbers Ana Dionísio <anadionisio257@gmail.com> - 2013-03-20 08:27 -0700
Re: Lists and Decimal numbers Wanderer <wanderer@dialup4less.com> - 2013-03-20 08:48 -0700
Re: Lists and Decimal numbers Peter Otten <__peter__@web.de> - 2013-03-20 16:52 +0100
Re: Lists and Decimal numbers Alister <alister.ware@ntlworld.com> - 2013-03-20 19:20 +0000
Re: Lists and Decimal numbers Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-03-20 19:53 +0000
Re: Lists and Decimal numbers Grant Edwards <invalid@invalid.invalid> - 2013-03-20 20:00 +0000
Re: Lists and Decimal numbers Alister <alister.ware@ntlworld.com> - 2013-03-20 20:47 +0000
csiph-web