comparing elements of a list with a string

Marc 'BlackJack' Rintsch bj_666 at gmx.net
Thu Sep 27 12:53:09 EDT 2007


On Thu, 27 Sep 2007 08:16:59 -0400, Steve Holden wrote:

> Shriphani wrote:
>> Hello,
>> Would that mean that if I wanted to append all the (date, time) tuples
>> to a list, I should do something like:
>> 
>> for file in list_of_backup_files:
>>     some_list.append(file)
> 
> That would be one way to do it (assuming you started with some_list as 
> an empty list). But a faster way would be to use a list comprehension 
> and say
> 
> some_list = [f for f in list_of_backup_files]

Or:

some_list = list(list_of_backup_files)

If `some_list` is not empty:

some_list.extend(list_of_backup_files)

Ciao,
	Marc 'BlackJack' Rintsch



More information about the Python-list mailing list