slice with negative stride
I'm really confused about results of slices with negative strides. For
example
>>mystr = 'my string'
I would have then thought of the contents of mystr as:
indices0 1 2 3 4 5 6 7 8
contentm y s t r i n g
with mystr[:3] = 'my '
Can someone explain to me how mystr[:3:-1] = 'gnirt'?
I was expecting the result to be mystr[:3] reversed (' ym') i.e slice
then reverse or even the first 3 elements of the string after being
reversed ('gni') i.e. reverse then slice.
Thanks
Andy
--
http://mail.python.org/mailman/listinfo/python-list
flatten sequences in a dictionary
Hi I wondering if someone could give me a pointer. I have a dictionary with the following structure: testDict = dict(foo=((1,2,3),(1,4,3)), bar=((3,2,1),(9,8,7,)), mumble=((1,2,3),)) I am trying to create a list of the the 3 element tuples using itertools (just for a bit of fun). I'm trying this: list(itertools.chain(testDict.itervalues()) but that's doesn't work. I think I need a way to convert the iterator returned by itervalues() into a sequence of iterables. Any clues? Thanks Andy -- http://mail.python.org/mailman/listinfo/python-list
Re: ISO Python example projects (like in Perl Cookbook)
Have a look at Dive into Python by Mark Pilgrim. It is available for free here http://www.diveintopython.org/. Andy -- http://mail.python.org/mailman/listinfo/python-list
Test driven development
Hi Sorry if this is a bit off topic but as unit testing is such a cornerstone of python development I thought a few of you may be able to share your knowledge/experiences. I like the concept of TDD but find it difficult to put into practice most of the time. I think this primarily because I tend to like top- down development and functional/object decomposition and TDD feels more like a bottom-up approach. So my question is when approaching a project that you want to employ test driven development on how and where do you start? And also if anyone uses top-down design with TDD I would be interested in how you do it (does it involve lots of mock objects/ is the first test you write the last one to pass)? Thanks Andy -- http://mail.python.org/mailman/listinfo/python-list
