Page 1 of 1

Arrays pop()?

Posted: Tue Jun 08, 2021 7:20 am
by lofer
What for arrays are if it is impossible to pop() anything from them in micropython?
I would love to use them instead of lists but how?

Re: Arrays pop()?

Posted: Wed Jun 09, 2021 4:39 am
by pythoncoder
You access them by index or by slice notation (a[4:10]). You can also create generators from them:

Code: Select all

a = array.array('I', range(32))
i = (x for x in a if x > 4)
b = array.array('I', i)
Arrays are much less flexible than lists but they are highly efficient as elements are stored in contiguous memory locations. Consequently they are useful for passing data to and from code written using the inline assembler, and are a natural for writing device drivers for chips that provide memory such as Flash or EEPROMs.