Concatenate list values
Mark Lawrence
breamoreboy at yahoo.co.uk
Mon Feb 23 12:13:54 EST 2015
On 23/02/2015 16:14, Tim Chase wrote:
> On 2015-02-23 07:58, loial wrote:
>> Is there a quick way to concatenate all the values in a list into a
>> string, except the first value?
>>
>> I want this to work with variable length lists.
>>
>> All values in list will be strings.
>
> Using
>
> "".join(my_list[1:])
>
> should work.
>
> If it is an arbitrary iterable instead of a list (and thus can't be
> sliced), you can use
>
> "".join(itertools.islice(my_iter, 1, None))
>
> -tkc
>
Presumably rather more efficient for long lists as you're not taking a
copy of (effectively) the entire list. Any volunteers to measure it,
not mentioning any names, Mr D'Aprano? :)
--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.
Mark Lawrence
More information about the Python-list
mailing list