On Wed, Mar 4, 2015 at 12:04 PM, Alan Gauld <alan.ga...@btinternet.com> wrote: > On 04/03/15 15:40, niyanax...@gmail.com wrote: >> >> Need help trying to implement insert, remove, indexof, and reverse >> functions. >> >> I tried to do them but am not sure if it is correct. I am struggling with >> arrays. > > > I;m not sure why so many courses seem to insist on teaching old school > arrays using Python. It involves rewriting functions that already exist, in > superior form in the standard library. Reinventing the wheel is a bad > practice and it seems a shame that some teachers appear to want to teach bad > habits!
Alan's comments here have got me to wondering. I originally first learned of programming via FORTRAN and BASIC (various incarnations). These used multidimensional array-based thinking. Of course, these were (then) primarily used to process numerical data. And that is what I used them for. I don't recollect anything similar to Python lists in those languages way back then. In doing physics-related programming it was not unusual to have a need for 3- or 4-dimensional arrays, and sometimes more. OTH, Python lists are *very* flexible in how they can be implemented and especially in what can be stored (objects they point to) in them. So I thought I would ask the question: What are the strengths and weaknesses of Python lists compared to "old school" arrays? 1) If the data involved is strictly numerical, does this alter your answer? Especially if multidimensional matrix calculations are involved? 2) If either numerical or string data is allowed to be stored, does this change your answer? 3) Have "old school" arrays evolved into something more flexible in most programming languages? 4) Are there other clarifying questions I should be asking on this topic that are not occurring to me? [...] > If Array returns a fixed size array can't you just always assign to the > index position. In other words does the array need to be filled > in a sequential manner or could you have a 'hole' in the middle (one of the > few things an array allows that a list doesn't - although you can just use a > dictionary if that's really important! What is a complete list of the "things" array-style thinking allow, but that Python lists don't? And for those "things", what would be a Python way of handling them? One thing that I have noticed in my recent Python efforts is that when I am implementing an array-like object as a list, that when the number of dimensions gets beyond two, the Python method of addressing individual data items seems a bit clunky to me. For instance, if I wanted to address an item in a 3-dimensional array, I would use something like (x, y, z) whereas the Python list form amounts to [x][y][z] . Of course, all attempts to print out an entire array or list if n >= 3 will not display well. But this slight "clunkiness" in addressing pales in comparison to the power and flexibility of the "stuff" I can store in a list compared to an array (unless they have substantially evolved). And I have greatly enjoyed making use of this flexibility! -- boB _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor