#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2004
    Posts
    2
    Rep Power
    0

    help,very easy question i think


    I have a list like this list =[aaa.123,bbb,456]
    I want to split with "." and assin each part of list to a new list like mylist0 = [aaa,123] and mylist1 =[bbb,456]
    so I do

    list =[aaa.123,bbb,456]
    i = 0
    while i < len(list):
    s = list[i]
    mylist+str(i)=s.split(".")
    i=i+1
    print mylist0

    But i got error "can't assign to operator".
    Could anyone help me slove this problem?
  2. #2
  3. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    You cant create dynamic variables like that saddly. And in most cases i wouldn't even try since a list would be much easier to use etc. You should also note that in order to split a value it has to be a string; not a literal.

    Code:
    #!/usr/bin/env python
    
    array = ['aaa.123', 'bbb.456']
    
    for (index, value) in enumerate(array):
    	array[index] = value.split('.')
    	print value
    If you really want to declair dynamic variables then you should look at the exec keyword. Look for it in this page:

    http://www.python.org/doc/current/lib/built-in-funcs.html

    Mark.
    programming language development: www.netytan.com Hula

  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2004
    Posts
    2
    Rep Power
    0
    Originally Posted by netytan
    You cant create dynamic variables like that saddly. And in most cases i wouldn't even try since a list would be much easier to use etc. You should also note that in order to split a value it has to be a string; not a literal.

    Code:
    #!/usr/bin/env python
    
    array = ['aaa.123', 'bbb.456']
    
    for (index, value) in enumerate(array):
    	array[index] = value.split('.')
    	print value
    If you really want to declair dynamic variables then you should look at the exec keyword. Look for it in this page:

    http://www.python.org/doc/current/lib/built-in-funcs.html

    Mark.
    Thank you very much.

IMN logo majestic logo threadwatch logo seochat tools logo