Re: Is there a better way to do this snippet?

2012-04-03 Thread nn
On Apr 3, 12:26 pm, Alain Ketterlin wrote: > nn writes: > >> > for item in tag23gr: > >> > ...        value, key = tuple(item) > >> > ...        if(g23tag.get(key)): > >> > ...                g23tag[key].append(value) > >> > ...        else: > >> > ...                g23tag[key] = [value] > > >>

Re: Is there a better way to do this snippet?

2012-04-03 Thread Alain Ketterlin
nn writes: >> > for item in tag23gr: >> > ...        value, key = tuple(item) >> > ...        if(g23tag.get(key)): >> > ...                g23tag[key].append(value) >> > ...        else: >> > ...                g23tag[key] = [value] >> >> for item in tag23gr: >>     g23tag.setdefault(item[0],[]).

Re: Is there a better way to do this snippet?

2012-04-03 Thread nn
On Apr 3, 11:02 am, Alain Ketterlin wrote: > python writes: > > tag23gr is a list of lists each with two items. > > g23tag is an empty dictionary when I run the for loop below. > > When is is complete each key is a graphic name who's values are a list > > of tags. > > > for item in tag23gr: > > .

Re: Is there a better way to do this snippet?

2012-04-03 Thread Peter Otten
python wrote: > I played around with a few things and this works but was wondering if > there was a better way to do this. > My first thought was list comprehension but could not get a figure out > the syntax. > > tag23gr is a list of lists each with two items. > g23tag is an empty dictionary whe

Re: Is there a better way to do this snippet?

2012-04-03 Thread Chris Angelico
On Wed, Apr 4, 2012 at 12:36 AM, python wrote: > for item in tag23gr: > ...     value, key = tuple(item) > ...     if(g23tag.get(key)): > ...             g23tag[key].append(value) > ...     else: > ...             g23tag[key] = [value] Simple enhancement: Use setdefault. Instead of the if, just u

Re: Is there a better way to do this snippet?

2012-04-03 Thread Alain Ketterlin
python writes: > tag23gr is a list of lists each with two items. > g23tag is an empty dictionary when I run the for loop below. > When is is complete each key is a graphic name who's values are a list > of tags. > > for item in tag23gr: > ... value, key = tuple(item) > ... if(g23tag.get(key))

Is there a better way to do this snippet?

2012-04-03 Thread python
I played around with a few things and this works but was wondering if there was a better way to do this. My first thought was list comprehension but could not get a figure out the syntax. tag23gr is a list of lists each with two items. g23tag is an empty dictionary when I run the for loop below. W

Re: Is there a better way to do this?

2010-03-01 Thread Richard Brodie
"Matt Mitchell" wrote in message news:mailman.65.1267464765.23598.python-l...@python.org... > My initial idea was to make a list of all the different > ways "project" has been capitalized in my repo and try each one. The > code looks like this: I would use pysvn.Client.list to get a list of fi

Is there a better way to do this?

2010-03-01 Thread Matt Mitchell
Hi, I wrote a python script that uses pysvn to export projects from an svn repo I have. The repo has hundreds of projects in it with a directory structure that is pretty uniform however it's not exactly uniform because of the capitalization. I.e.: \root \project English \Stuff \Stu

Re: thanks very much indeed for your help is there a better way to do this (python3) newby

2009-02-24 Thread kshitij
On Feb 24, 6:29 am, "Rhodri James" wrote: > On Mon, 23 Feb 2009 23:33:31 -, Gary Wood wrote: > > '''exercise to complete and test this function''' > > import string > > def joinStrings(items): > >     '''Join all the strings in stringList into one string, > >     and return the result. For ex

Re: thanks very much indeed for your help is there a better way to do this (python3) newby

2009-02-23 Thread Rhodri James
On Mon, 23 Feb 2009 23:33:31 -, Gary Wood wrote: '''exercise to complete and test this function''' import string def joinStrings(items): '''Join all the strings in stringList into one string, and return the result. For example: >>> print joinStrings(['very', 'hot', 'day']) '

thanks very much indeed for your help is there a better way to do this (python3) newby

2009-02-23 Thread Gary Wood
'''exercise to complete and test this function''' import string def joinStrings(items): '''Join all the strings in stringList into one string, and return the result. For example: >>> print joinStrings(['very', 'hot', 'day']) 'veryhotday' ''' for i in items: return (''

File/Directory hacks - is there a better way to do this?

2005-02-23 Thread Fitzgerald Steele
I had a software package screw up a directory tree by placing all the files in a directory of the same name. So I wound up with: Root file1.txt (dir) file1.txt (file) file2.txt (dir) file2.txt (file) Annoying. So I wrote the following script, which fixed the problem by renaming a