merging lists
Greg Jorgensen
gregj at pobox.com
Tue Mar 21 04:53:26 EST 2000
More information about the Python-list mailing list
Tue Mar 21 04:53:26 EST 2000
- Previous message (by thread): merging lists
- Next message (by thread): file manipulation and write permission
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
"55555" <55555 at dakotacom.net> wrote in message news:38d73758_1 at news5.newsfeeds.com... > I'm trying to lay out two lists of strings next to each other with a tab > in between. For example: > > incList = ['asdf', 'zxcv'] > decList = ['sdfg', 'dgfh', 'wert'] > > a = map(lambda x,y: x+'\t'+y, incList, decList) > > I get a type error mentioning something about bad operand types. Is there > either an easier way to do this, or could someone explain what I'm doing > wrong? The problem is the lists aren't the same length. map will get None values from the shorter list(s), but the + operator can't concatenate a string with None. If you can't be sure the lists are the same length, you can do something like this: def join(s,t): if s == None: s = '' if t == None: t = '' return str(s) + '\t' + str(t) ... a = map(join, incList, decList) Greg Jorgensen gregj at pobox.com
- Previous message (by thread): merging lists
- Next message (by thread): file manipulation and write permission
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list