function for not repeating loop

Asked

Viewed 54 times

0

deze = []
df["1_Dezena"][0:10]
for a in (df["1_Dezena"][0:10]):
    deze.append(int(a))
    print(deze)

Upshot:

[41]

[41, 9]

[41, 9, 36]

[41, 9, 36, 6]

[41, 9, 36, 6, 1]

[41, 9, 36, 6, 1, 19]

[41, 9, 36, 6, 1, 19, 56]

[41, 9, 36, 6, 1, 19, 56, 53]

[41, 9, 36, 6, 1, 19, 56, 53, 55]

[41, 9, 36, 6, 1, 19, 56, 53, 55, 25]

But I would like it to appear: [41, 9, 36, 6, 1, 19, 56, 53, 55, 25].

Could someone help me?

1 answer

1

Hello.

You are using print method inside the for and each loop is showing the current value of the tens, use when the is finished.

Solution:

deze = []
df = {"1_Dezena": [0,1,2,1,21,3,4,8,4,34]}
df["1_Dezena"][0:10]
for a in (df["1_Dezena"][0:10]):
    deze.append(int(a))
print(deze)

  • Thank you so much for your help... I managed to solve

  • Thank you so much for your help... I managed to solve

  • Thank you so much for your help... I managed to resolve with your correction.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.