Re: Python arrays and sting formatting options



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
.



Relevant Pages

  • Re: [perl-python] combinatorics fun
    ... > instead of array for this program. ... def combo: ... import pprint ... Computer Science Dept., Univ. of California, Irvine ...
    (comp.lang.python)
  • Re: [perl-python] combinatorics fun
    ... > instead of array for this program. ... def combo: ... import pprint ... Computer Science Dept., Univ. of California, Irvine ...
    (comp.lang.perl.misc)
  • [SUMMARY] Records and Arrays (#170)
    ... quiz problem isn't necessary. ... or gets initialized to an empty array. ... important since we can refer to the original data. ... def initialize ...
    (comp.lang.ruby)
  • [SUMMARY] DayRange (#92)
    ... A couple of submitters mentioned that this problem isn't quite as simple as it ... def test_english ... This is the heart of the String building process and many solutions landed on ... Array of Arrays with the days divided into groups of start and end days. ...
    (comp.lang.ruby)
  • Re: Special characters and superscripts in PostScript and EPS
    ... When does one use bind def and load def? ... what you actually are doing is creating an executable array on the stack ... When you execute the array, if it contains any names the interpreter ... The 'load' operator searches dictionaries looking for a named value. ...
    (comp.lang.postscript)