Re: Python arrays and sting formatting options
- From: Ivan Reborin <ireborin@xxxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 30 Sep 2008 15:42:58 +0200
On 30 Sep 2008 07:07:52 GMT, Marc 'BlackJack' Rintsch <bj_666@xxxxxxx>
wrote:
Hello Marc, thanks for answering (on both subjects). I understand now
the logic which lays behind what you were explaining in the other one.
It cleared things quite a bit.
Well, I don't know if this qualifies as equivalent:
=====
from __future__ import with_statement
from functools import partial
from itertools import islice
from pprint import pprint
def read_group(lines, count):
return [map(int, s.split()) for s in islice(lines, count)]
def main():
result = list()
with open('test.txt') as lines:
lines = (line for line in lines if line.strip())
result = list(iter(partial(read_group, lines, 3), list()))
pprint(result, width=30)
if __name__ == '__main__':
main()
=====
I'm afraid I must admit I find the code above totally uncomprehesible
(I can't even see where the array here is mentioned - "result"?) and
inpractical for any kind of engineering practice I had in mind.
Does python, perchance, have some wrapper functions or something,
which would allow one to load an array in a more natural "technical"
way ? Like something mentioned above in my post (now deleted) ?
Also, is there a way to change counter for arrays to go from 0 to 1 ?
(first element being with the index 1) ?
(probably not since that seems like a language implementation thing,
but it doesn't hurt to ask)
--
Ivan
.
- Follow-Ups:
- Re: Python arrays and sting formatting options
- From: Marc 'BlackJack' Rintsch
- Re: Python arrays and sting formatting options
- References:
- Python arrays and sting formatting options
- From: Ivan Reborin
- Re: Python arrays and sting formatting options
- From: Marc 'BlackJack' Rintsch
- Python arrays and sting formatting options
- Prev by Date: Re: writing dll in python?
- Next by Date: Re: Python is slow?
- Previous by thread: Re: Python arrays and sting formatting options
- Next by thread: Re: Python arrays and sting formatting options
- Index(es):
Relevant Pages
|