How can I optimize the code to parse lines in a file?
Suggest not adding a new mesh for every object,
bpy.ops.mesh.primitive_ico_sphere_add

Instead you can add a sphere once, then reuse the mesh between all objects changing their scale. Its also possible for each object to have their own material so you can still share object data but have different colors.

Though you could even make do with a single material for all and just use object color.