You could actually initialize rr,cc, val directly with these lists and skip the extend part.