Page 1 of 1

Epython Lists

PostPosted: Mon Sep 11, 2017 12:15 pm
by mgentry10
How can I work with lists in epython? Say I want to create an empty list and ".append" to it, how would that work?

Re: Epython Lists

PostPosted: Wed Sep 20, 2017 8:43 am
by polas
Hi,

Yes but lists can not be dynamic - for instance you can do something like:

Code: Select all
data=[0]*10
to create a list of size 10, each element set to zero. In the array module you can create multi dimensional array such as
Code: Select all
a=array(100,100)
also with functionality to determine meta data (size, number of dimensions etc for arrays and lists.) As I say there is no support for dynamically extending lists/arrays (not least because this is expensive in terms of runtime & memory usage) but you could implement this yourself, something like:

Code: Select all
from array import *

def append(arr, element):
  s=size(arr)
  newarray=arr(s+1)
  i=0
  while i < s:
      newarray[i]=arr[i]
      i+=1
  newarray[s]=element
  return newarray


Cheers,
Nick