slice with negative stride

2007-10-06 Thread ajcppmod
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

2008-01-09 Thread ajcppmod
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)

2008-01-10 Thread ajcppmod
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

2008-01-24 Thread ajcppmod
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