Epython Lists

Discussion about Parallella (and Epiphany) Software Development

Moderators: amylaar, jeremybennett, simoncook

Epython Lists

Postby mgentry10 » Mon Sep 11, 2017 12:15 pm

How can I work with lists in epython? Say I want to create an empty list and ".append" to it, how would that work?
mgentry10
 
Posts: 4
Joined: Sun Jun 11, 2017 3:46 am

Re: Epython Lists

Postby polas » Wed Sep 20, 2017 8:43 am

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
polas
 
Posts: 46
Joined: Thu Mar 05, 2015 9:41 pm


Return to Programming Q & A

Who is online

Users browsing this forum: No registered users and 6 guests