How to get and ascribe irregular numbers to objects?
<p>I am a beginner and I have a question.
I have datas in csv file, I can find 100 objects and irregular number of size number for each object. In one row I have a name of the object, its size and then these irregular numbers- for one name it can be 20 of then and for the other 40. </p>

<pre><code>import glob
import csv
import re
for f_name in glob.glob("*.csv"):
with open(f_name) as f:
    reader = csv.reader(f,  delimiter=',')
    for row in reader: 
       print (row[1]) 
</code></pre>

<p>how can I have the numbers which are irregular? any loop? and how can I ascribe the numbers to the "size" and "name"? </p>

<pre><code>with open('data.csv') as fp:
  for line in fp:
     data = line.split(',')
     if data[0] == 'name':
       result[name] = init_dict(name)
     elif data[0] == 'weight' :
       update_dict(data[1])
     else:
       update_dict(data[0])
</code></pre>

<p>basically you can just loop through the file and whenever you encounter a name just create a new_dict and update the corresponding attribute until you encounter the new name</p>

<pre><code>def init_dict(name):
  return {'name': name, 'weight':None, 'others':None}
</code></pre>

<p>similary you can write an update dict to update the corresponding attributes of the dict of that corresponding name</p>

python