0

I'm writing a code and I have a problem. I have different lists named xx1 and xx2, etc. I have a function like this:

def dotfind(n):
    xone=xdis[n-1]
    xtwo=xdis[n]
    t=toc[n]
    while xone<xtwo:
        t=t+1
        xdis[n-1]=(a*(t**2))/2
        v=a*t
        if xone>=xtwo:
            t=t-1
            v=a*t
    else:
         xx.append( x );
         vv.append( v );
         tt.append( t );  

Okay. Don't pay attention to the whole function. Just look at the else part.

If I want the program to get the "n" and append those variables v & x & t to the xx and vv and tt number n, how can it be done?
This is what I mean: for example if n is 1 then it should do the process on lists xx1 and xx2 and xx3 , if my n is 2, then it should append v & x & t to xx2 and vv2 and tt2, ... .
Please help me!

Ali Tohidi
  • 73
  • 7
  • This is better implemented by defining a list named `xx` and indexing it using `xx[n]` instead of declaring multiple variables like `xx1`, `xx2` etc. You _can_ have lists inside lists. – Selcuk Apr 19 '16 at 03:34
  • Either use a dictionary like suggested in the dupe, or use a regular list like suggested by @Selcuk if your names only differ by adjacent numeric indices. – timgeb Apr 19 '16 at 03:51
  • Also don't use any of the horrible answers in the dupe that suggest using `globals()`, `locals()` or `exec`/`eval` :) – timgeb Apr 19 '16 at 03:56

0 Answers0