Fwd: string concatenate

sandric ionut sandricionut at yahoo.com
Wed Oct 1 19:03:50 CEST 2008


Thank you:
 
but I would like to have them not like:
['name1', 'name2', 'name3', 'name4', 'name5', 'name6', 'name7',  
'name8', 'name9']
 
but like
name1 name2 name3 name4 name5 name6 name7 name8 name9
 
Is it possible?
 
Ionut



----- Original Message ----
From: Tommy Grav <tgrav at mac.com>
To: Python List <python-list at python.org>
Sent: Wednesday, October 1, 2008 7:50:25 PM
Subject: Fwd: string concatenate

On Oct 1, 2008, at 12:41 PM, sandric ionut wrote:

> Hi:
>
> I have the following situation:
>    nameAll = []
>    for i in range(1,10,1):
>        n = "name" + str([i])
>        nameAll += n
>    print nameAll
>
> I get:
>
> ['n', 'a', 'm', 'e', '[', '1', ']', 'n', 'a', 'm', 'e', '[', '2',  
> ']', 'n', 'a', 'm', 'e', '[', '3', ']', 'n', 'a', 'm', 'e', '[',  
> '4', ']', 'n', 'a', 'm', 'e', '[', '5', ']', 'n', 'a', 'm', 'e',  
> '[', '6', ']', 'n', 'a', 'm', 'e', '[', '7', ']', 'n', 'a', 'm',  
> 'e', '[', '8', ']', 'n', 'a', 'm', 'e', '[', '9', ']']
>
> but I would like to have it as:
>
> name1 name2 name3 ...name10
>
> How can I do it?
>
> Thank you,
>
> Ionut

> nameAll = []
> for i in xrange(1,10,1):
>    n = "name" + str(i)
>    nameAll.append(n)
> print nameAll
['name1', 'name2', 'name3', 'name4', 'name5', 'name6', 'name7',  
'name8', 'name9']

list.append() is the right tool for adding new elements to a list.

Cheers
  Tommy

--
http://mail.python.org/mailman/listinfo/python-list



      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20081001/835dc713/attachment.html>


More information about the Python-list mailing list