Creating A Tuple From A List, Adding To Tuple As You Do

Jeff Nyman jeffnyman at gmail.com
Thu Jun 5 14:41:28 CEST 2008


Greetings all.

The subject line of this thread is probably one of the worst ever. I
was trying to encapsulate what I am doing. Based on my new-found
knowledge from another thread, I'm able to get a list of directories
and they come to me in the form of a list. Here is an example:

from glob import glob
DC_List = glob('\\\\vcdcflx006\\Flex\\Sites\\*\\')
DC_List = ['Baltimore', 'Birmingham', 'Cincinnati', 'Cleveland',
LosAngeles']

(Each element in the DC_List is actually a full directory path, but I
shortened that in the interest of clarity.)

The problem is that I need to pass this list to a list control in a
wxWidgets application. In order to do that, I need to pass in a list
like this:

[ ('Baltimore', ''), ('Birmingham', ''), ('Cincinnati', ''),
('Cleveland', ''), ('LosAngeles', '') ]

In other words, each element in the list is a tuple that has an empty
second string. The problem I'm having is in converting my list above
to be of this type. I can't do append because that (logically) puts
everything at the end. I did try this:


for count in range(0, len(DC_List)):
    DC_List.insert(count, '')


Here I was thinking I could insert a '' into the right place after
each entry in the list. That doesn't quite work. Does anyone have an
idea of a good approach here? (I did search on tuples and lists and
while I found a lot of information about both, I couldn't find a
solution that did what I'm discussing above.)

- Jeff



More information about the Python-list mailing list