|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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
|
||||
|
||||
|
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. |
|
#3
|
|||
|
|||
|
Quote:
Thank you very much. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Python Programming > help,very easy question i think |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|