Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a dynamic list in Python? [closed]

Tags:

python

loops

How to create a dynamic list in Python. I am trying to prepare a Array where the value will be pushed dynamically into it (using a loop)

like image 884
aNikhil Avatar asked Apr 23 '16 14:04

aNikhil


People also ask

Does Python have dynamic list?

Python lists are dynamic if you what you are asking is that they resize whenever an element is appended to them.

How do you define a dynamic list?

A dynamic list combines the power and flexibility that a fragment would have with contribution capabilities. The dynamic list performs a query in the content server, displays the files that match that query, and allows contributors to modify those files, even add new ones.


1 Answers

Try this one: Initialize with a variable x and the append into this array x inside a for loop as below:

x = []
n = input("enter length")
for i in range(1, int(n)):
    k=input("enter value")
    x.append(k) # push your entered value

print x

You can append any value in the loop as x.append(value).

like image 191
krishna Prasad Avatar answered Sep 23 '22 10:09

krishna Prasad