Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a list with >255 elements

Ok, so I'm writing some python code (I don't write python much, I'm more used to java and C).

Anyway, so I have collection of integer literals I need to store. (Ideally >10,000 of them, currently I've only got 1000 of them) I would have liked to be accessing the literals by file IO, or by accessing there source API, but that is disallowed. And not ontopic anyway.

So I have the literals put into a list:

    src=list(0,1,2,2,2,0,1,2,... ,2,1,2,1,1,0,2,1)
#some code that uses the src

But when I try to run the file it comes up with an error because there are more than 255 arguments. So the constructor is the problem. How should I do this?

The data is intitally avaiable to me as a space deliminated textfile. I just searched and replaced and copied it in

like image 266
Lyndon White Avatar asked Sep 14 '10 04:09

Lyndon White


People also ask

How do I make a list of 100 numbers in Python?

Python Create List from 0 to 100. A special situation arises if you want to create a list from 0 to 100 (included). In this case, you simply use the list(range(0, 101)) function call. As stop argument, you use the number 101 because it's excluded from the final series.

How do I make a list of certain lengths in Python?

To create a list of n placeholder elements, multiply the list of a single placeholder element with n . For example, use [None] * 5 to create a list [None, None, None, None, None] with five elements None . You can then overwrite some elements with index assignments.

How do you initialize a list size?

You can initialize a list of a custom size using either multiplication or a range() statement. The multiplication method is best if you want to initialize a list with the same values. A range() statement is a good choice if you want a list to contain values in a particular range.

How do I make a list of sequential numbers in Python?

Python comes with a direct function range() which creates a sequence of numbers from start to stop values and print each item in the sequence. We use range() with r1 and r2 and then convert the sequence into list.


2 Answers

If you use [] instead of list(), you won't run into the limit because [] is not a function.

src = [0,1,2,2,2,0,1,2,... ,2,1,2,1,1,0,2,1]
like image 183
sepp2k Avatar answered Oct 01 '22 01:10

sepp2k


src = [int(value) for value in open('mycsv.csv').read().split(',') if value.strip()]

Or are you not able to save text file in your system?

like image 31
Tony Veijalainen Avatar answered Oct 01 '22 01:10

Tony Veijalainen