Forum Archive

Help needed for an Array? Use Cases

adrius42

I wish to create a blank array of 100 elements
Where blank is either Integer 0 or Empty string ‘“” (two different use cases)
Then I wish to write to specific elements in the array
Either replacing the elements or adding/appending to them
Having read and re read the documents

I have not been able fathom how to accomplish these tasks.
I recall in Algol that this was a trivial task, it was how I ”cheated” doing a sort task,
According to my professor in doing a sort. He wanted a bubble sort.
I simply wrote the numbers into an array where n= array element, and then read them out

How!? In Python?

Is a command missing from the documentation?

cvp

@adrius42

    a =[0]*100
    print(a)
ccc

sorted() is your friend... https://docs.python.org/3/howto/sorting.html

adrius42

OMG why did I try a read the manual, I found a part in the manual that showed me that *100 would not work!?

And yet it all did!

a=[0]*100
print(a)
a[10]=1
print(a)
a[10]=a[10]+1
print(a)
b=['']*100
print(b)
b[10]='test'
print(b)
b[10]=b[10]+'again'
print(b)

Btw I wasn’t trying to do a sort that was just a historical side comment, but thanks for the pointer, stored for future reference.

Adrius42

markfilan

try Python...list.sort()