Re: file I/O and arithmetic calculation

2013-05-23 Thread Keira Wilson
not exactly for the homework, but as my starting point of learning thank you so much. -- http://mail.python.org/mailman/listinfo/python-list

RE: file I/O and arithmetic calculation

2013-05-23 Thread Carlos Nepomuceno
> From: denismfmcma...@gmail.com [...] >> Dear all who involved with responding to my question - Thank you so much >> for your nice code which really helped me. > > Hold on a sec? Someone posted code that gave the correct answer to a > homework question? > >

Re: file I/O and arithmetic calculation

2013-05-23 Thread Denis McMahon
On Thu, 23 May 2013 07:17:58 -0700, Keira Wilson wrote: > Dear all who involved with responding to my question - Thank you so much > for your nice code which really helped me. Hold on a sec? Someone posted code that gave the correct answer to a homework question? -- Denis McMahon, denismfmcma.

Re: file I/O and arithmetic calculation

2013-05-23 Thread Keira Wilson
Dear all who involved with responding to my question - Thank you so much for your nice code which really helped me. -- http://mail.python.org/mailman/listinfo/python-list

Re: file I/O and arithmetic calculation

2013-05-23 Thread Chris Angelico
On Thu, May 23, 2013 at 10:37 AM, Carlos Nepomuceno wrote: > >> From: oscar.j.benja...@gmail.com >> Date: Thu, 23 May 2013 01:34:37 +0100 >> Subject: Re: file I/O and arithmetic calculation >> To: carlosnepomuc...@outlook.com &g

Re: file I/O and arithmetic calculation

2013-05-23 Thread Oscar Benjamin
On 23 May 2013 04:15, Carlos Nepomuceno wrote: > The last line of my noob piece can be improved. So this is it: Most of it can be improved. > filenames = ['1.txt', '2.txt', '3.txt', '4.txt', '5.txt'] > contents = [[[int(z) for z in y.split(',')] for y in open(x).read().split()] > for x in file

RE: file I/O and arithmetic calculation

2013-05-22 Thread Carlos Nepomuceno
The last line of my noob piece can be improved. So this is it: ### 1strow_average.py ### #Assuming you have CSV (comma separated values) files such as: #1.txt = '0,1,2,3,4,5,6,7,8,9\n' \ #    '10,11,12,13,14,15,16,17,18,19\n' \ #    '20,21,22,23,24,25,26,27,28,29\n' ... # # Usage: contents

RE: file I/O and arithmetic calculation

2013-05-22 Thread Carlos Nepomuceno
> From: oscar.j.benja...@gmail.com > Date: Thu, 23 May 2013 01:34:37 +0100 > Subject: Re: file I/O and arithmetic calculation > To: carlosnepomuc...@outlook.com > CC: python-list@python.org > > On 23 May 2013 00:49, Carlos Nepomuceno

Re: file I/O and arithmetic calculation

2013-05-22 Thread Oscar Benjamin
On 23 May 2013 00:49, Carlos Nepomuceno wrote: > > The code is pretty obvious to me, I mean there's no obfuscation at all. I honestly can't tell if you're joking. -- http://mail.python.org/mailman/listinfo/python-list

RE: file I/O and arithmetic calculation

2013-05-22 Thread Carlos Nepomuceno
> From: denismfmcma...@gmail.com [...] > > import re > def v(s): > l=len(s) > t=0. > for i in range(l): > t=t+(abs(ord(s[i]))*1.) > return t/(l*1.) > for n in range(5): > m="c:/test/"+str(n+1)+".txt" > f=open(m,"r") > d=[] > t=0. > for l in range(10): > d=d+

Re: file I/O and arithmetic calculation

2013-05-22 Thread Denis McMahon
On Thu, 23 May 2013 01:13:19 +0900, Keira Wilson wrote: > I would appreciate if someone could write a simple python code for the > purpose below: Didn't have your data, so couldn't verify it completely, but try this: import re def v(s): l=len(s) t=0. for i in range(l): t=t+(abs(ord(s[i]))*1

RE: file I/O and arithmetic calculation

2013-05-22 Thread Carlos Nepomuceno
># contents[3][4][5] : 6th column of 5th row of file '4.txt' BTW, it should read # contents[3][4][5] : 6th value of 5th row of file '4.txt' -- http://mail.python.org/mailman/listinfo/python-list

RE: file I/O and arithmetic calculation

2013-05-22 Thread Carlos Nepomuceno
> From: oscar.j.benja...@gmail.com [...] > > Do you find this code easy to read? I wouldn't write something like > this and I certainly wouldn't use it when explaining something to a > beginner. > > Rather than repeated list comprehensions you should conside

Re: file I/O and arithmetic calculation

2013-05-22 Thread Oscar Benjamin
On 22 May 2013 22:05, Carlos Nepomuceno wrote: > > filenames = ['1.txt', '2.txt', '3.txt', '4.txt', '5.txt'] > contents = [[[int(z) for z in y.split(',')] for y in open(x).read().split()] > for x in filenames] > s1c = [sum([r[0] for r in f]) for f in contents] > a1r = [sum(f[0])/float(len(f[0]

RE: file I/O and arithmetic calculation

2013-05-22 Thread Carlos Nepomuceno
Funny! I made a lot of assumptions regarding your requirements specification. Let me know if it isn't what you need: ### 1strow_average.py ### #Assuming you have CSV (comma separated values) files such as: #1.txt = '0,1,2,3,4,5,6,7,8,9\n' \ #    '10,11,12,13,14,15,16,17,18,19\n' \ #    '2

Re: file I/O and arithmetic calculation

2013-05-22 Thread Mark Lawrence
On 22/05/2013 17:13, Keira Wilson wrote: Dear all, I would appreciate if someone could write a simple python code for the purpose below: I have five text files each of 10 columns by 10 rows as follows: |file_one= 'C:/test/1.txt' file_two= 'C:/test/2.txt' . . . file_five= 'C:/test/5.txt'|