list - Variable Assignments in Python -
i'm new programming , python, , i'm looking best way store information in program.
i'm looking store multiple values each item, don't know best way might this. like:
number: x position, y position, color
the problem have may have 1,000,000 numbers... make million dictionaries? , if do, efficiently able call on of them?
there 2 types of arrays in python. list() , tuple(). former mutable, whilst latter immutable. purpose of work, can assume list() may later modified, whilst tuple() may not.
to honest, 100k data not handle python. simple ordinary differential equation produce more that!
so, can this:
store individual arguments in tuples, ensure (a) data integrity, , (b) memory optimisation.
var = (35, 56, (123,23,213)) then add var list containing data.
data_container = list() data_container.append(var) .append(var), however, not efficient way it; every time append data, force copy of entire data in ram. better way initialise list beforehand, insert data later on. though this, need know how data input receive, or @ least willing set maximum!
this works follows:
data_container = [[]]*int(1e5) # list of 100,000 rows. following which, may use function add list. simplistic example. although i'm passing single numeric value, can have want. don't forget create door break out of loop! in instance, door value of input not being numeric (i.e. string, or empty). also, not handling maximum inputs in here, nor using conditions. once reach maximum number of rows, end indexerror. can either handle error , display "maximum reached" message, or increase capacity of list concatenating list rows. choice!
data_container = [[]]*int(1e1) max_capacity = len(data_container) ind = 0 def add2container(index, data): data_container[index] = data index += 1 return index while true: x = input('enter x: ') if a.isnumeric(): # python 3 feature. ind = add2container(ind, float(x)) else: break i hope answers question. if not, please go ahead , ask / explain further.
Comments
Post a Comment