Hmmn, the results were quite different from what I'd expected, for the first line in particular (I suspect my old Lisp biases are showing through on that one). I may need to go back to review certain aspects of the language.
Welcome to Daniweb Python Forum newbies ;). Even somebody could think that you do half decent code.
Actually the idea of exercise was something like this (thoughts of solver):
"""Hmmm, this is not really slice at all beginning is same as end, of course it is this first element. Tsk, Tsk, Tony trying to mislead me: In Python indexes start with zero, so it is then the second element 1 in list as list:  (WRONG)
And then the second one, OK I know this -1 step, it is one of favourite tricks here in Daniweb, it reverse this sequence, hey what this means... OK, starting from second last until the end, of course, so these two last ones are reversed, and then put them in... where? Oh this is the first slice, I saw this in documentation, where they explain insert function. So we insert at begining [10, 9], no ups, [9, 8], but are they going as one element like append or inside like with extend? The left side is slice, so they go like extend. So it will be [9, 8,.. I mean [0, 9, 8, 1, 2, 3, 4, 5, 6, 7] , no it continues, we did not move them but copy them:
[0, 9, 8, 1, 2, 3, 4, 5, 6, 7, 8, 9] (WRONG)"""
But tsk, tsk Vegaseat: that is obfuscating, I was not doing that. Even maybe PEP8 does not disallow that. Counting even odd is job for computer not for reader of your code:
print(list(reversed(a)) if len('-----') & 1 else a)
Griswolf: The infuriating thing is that you must have exactly correct number of elements in right hand side, Python does not drop extra ones or evaluate only the needed ones lazyly or give you access to expected number of lhs sequence elements to slice rhs accordingly. This however works with both odd and even number of elements.
Now enough time has passed that I can give some explanation for the questions:
Slice has length of difference of the start and end index, places are not in letter positions but between letters: [a] == a[1:2]. When beginning and end indexes are same the length is 0 so value is empty list .
a[1:1] = a[-2::-1]
means put between value 0 and 1, going one be one behind until the beginning (negative direction end) values from second last value including that. Result is therefore: [0, 8, 7, 6, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
Need some help with this Array. I am trying to get the sum of the even numbers and the sum of the odd numbers using a for each loop. I know the answers to what I am trying to achive are sum of even = 84 and the sum of ...
I have a 2d matrix with dimension (3, n) called A, I want to calculate the normalization and cross product of two arrays (b,z) (see the code please) for each column (for the first column, then the second one and so on).
the function that I created to find the ...