Python List Data Structure

From GM-RKB
Jump to navigation Jump to search

A Python List Data Structure is a Python array data structure that is a Python built-in data structure.



References

2016

  • https://docs.python.org/3/tutorial/datastructures.html#more-on-lists
    • QUOTE: The list data type has some more methods. Here are all of the methods of list objects:
      • list.append(x)
        Add an item to the end of the list. Equivalent to a[len(a):] = [x].
      • list.extend(L)
        Extend the list by appending all the items in the given list. Equivalent to a[len(a):] = L.

2013

  • (Melli, 2013-05-21) ⇒ Gabor Melli. (2013). “Python Array Examples."
Populate manually
Matrix = [[0 for x in xrange(5)] for y in xrange(6)] 
Matrix[4][3] = 99
Matrix

xx =  numpy.array([2, 4, -11])
yy = zeros(3, Int)        # Create empty array ready to receive result
Populate from a file.

Loops
for i in range(0, 3):
  Matrix[i] = i * 2
print yy
#    [4   8 -22]
Transforming into a string

Emptying

Random
import random;
#Generate 1000 random integer numbers which are between 1 and 9999(included).
Z=random.sample(range(1,9999),1000);
type(Z)