Determining the length of strings in a list

robin.siebler at palmsource.com robin.siebler at palmsource.com
Sun Mar 13 17:34:51 EST 2005


I have a dictionary.  Each key contains a list.  I am using the
contents of the list to build a portion of a command line.

However, before I can build the command line, I have to make sure that
the command isn't too long.  This means that I have to step through
each item in the list twice: once to check the length and once to build
the command.  Is there an easier/better way to do this?

for key in dict:
    tlen = 0
    for item in dict[key]:
        tlen = tlen + len(item)
    if tlen > 200:
        #break command portion into multiple portions ...
for key in dict:
    for item in dict[key]:
        #buld command




More information about the Python-list mailing list