Error in listing a Zip

asked 2023-03-22 16:22:41 +0200

Cyrille gravatar image

Until the end of this code all is fine

billes=[ZZ.random_element(0, 4) for i in range(50)]
 billes+=[ZZ.random_element(5, 10) for i in range(80)] 
billes+=[ZZ.random_element(10, 25) for i in range(21)]
    billes+=[ZZ.random_element(25, 50) for i in range(28)]
    billes+=[ZZ.random_element(50, 100) for i in range(28)]
    shuffle(billes)#no necessary here only to confirm
    billes1=sorted(billes)
    binbilles1=[[x for x in billes1 if 0 <= x < 4],[x for x in billes1 if 5 <= x < 10],[x for x in billes1 if 10 <= x < 25],[x for x in 
    billes1 if 25 <= x < 50],[x for x in billes1 if 50 <= x < 100]]
    avbinbilles1=[len(x)^(-1)*sum(x) for x in binbilles1]
    number=[len(x) for x in binbilles1]
    cumsumpop=[sum(number[:i]) for i in range(1, len(number)+1)]
    percumsumpop=[0]+[sum(number[:i])/sum(number) for i in range(1, len(number)+1)]
    cumsumavbinbilles1=[sum(avbinbilles1[:i]) for i in range(1, len(avbinbilles1)+1)]
    percumsumavbinbilles1=[0]+[sum(avbinbilles1[:i])/sum(avbinbilles1) for i in range(1, len(avbinbilles1)+1)]
    #percumbilles1=[0]+[sum(binbilles1[:i])/sum(number) for i in range(1, len(binbilles1)+1)]
    bool(len(percumsumavbinbilles1)==len(percumsumpop))

To plot a Lorenz curve I add

A=list(zip(percumsumavbinbilles1,percumsumpop))

as show by If you meant to plot two lists 'x' and 'y' against each other, use 'list_plot(list(zip(x,y)))' in https://doc.sagemath.org/html/en/reference/plotting/sage/plot/plot.html

But this generate an error 'list' object is not callable. Could somebody explain my mistake?

edit retag flag offensive close merge delete

Comments

A = list(zip(...)) worked for me, returning [(0, 0), (0.00968342644320298, 0.24154589371980675), (0.0633147113594041, 0.6280193236714976), (0.1931364724660814, 0.7294685990338164), (0.4530460228784251, 0.8647342995169082), (1.0, 1.0)].

John Palmieri gravatar imageJohn Palmieri ( 2023-03-22 17:08:52 +0200 )edit

WorksForMe(TM) in 10.0.beta4 (up to a formatting error in your code when pasted in my console : in Python/Sage, blank space is syntactic !)

BTW, this can be done much more easily in R ... which is quite easily callable from Sage.

Emmanuel Charpentier gravatar imageEmmanuel Charpentier ( 2023-03-22 19:20:20 +0200 )edit

My version is 9.7. But I encounter the same problem with 9.3. And sorry for the blank space. It was only a typesetting error not present in my original code. But I have tried this simple following code

B=[1.1, 2, 3]
C=[3, 4, 5]
D=list(zip(B,C))
D

which works in both versions.Then after this it works for my first exemple. I do not understand. Sorry

Cyrille gravatar imageCyrille ( 2023-03-22 23:18:45 +0200 )edit
1

Did you perhaps use list as a variable name? For example if you first did list = [1,2,3] and then later did list(zip(A,B)), you would get the error you described.

John Palmieri gravatar imageJohn Palmieri ( 2023-03-23 03:29:19 +0200 )edit