May-23-2018, 06:19 PM
Hello,
I have the following nested list:
Drive: /var Used Space: 60
Drive: /u01 Used Space: 60
Drive: /backups Used Space: 60
I tried the following code which gives me the first two columns above:
Any help would be greatly appreaciated.
Thanks!
I have the following nested list:
>>> print(list_mounts) [['/var', 71], ['/u01', 61], ['/backups', 69]]I'd like to print the list with the following output:
Drive: /var Used Space: 60
Drive: /u01 Used Space: 60
Drive: /backups Used Space: 60
I tried the following code which gives me the first two columns above:
>>> for i in list_mounts: ... print("Drive: ", i[0]) ... Drive: /var Drive: /u01 Drive: /backups...but when I try the following code, I receive errors:
>>> for x,y in list_mounts: ... print("Drive: ", x[0], "Used Space: ", y[0]) ... Traceback (most recent call last): File "<stdin>", line 2, in <module> TypeError: 'int' object is not subscriptable >>> for x,y in list_mounts(x,y): ... print("Drive: ", x[0], "Used Space: ", y[0]) ... Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: 'list' object is not callable >>> for x,y in list_mounts[x,y]: ... print("Drive: ", x[0], "Used Space: ", y[0]) ... Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: list indices must be integers or slices, not tupleI'm at a standstill trying to figure this out. Been trying different loops and searching Google to no avail.
Any help would be greatly appreaciated.
Thanks!