Skip to content

Instantly share code, notes, and snippets.

@BastinRobin
Created January 23, 2019 07:18
Show Gist options
  • Select an option

  • Save BastinRobin/bb5655d8355398fca1fcd07f1bd4bd90 to your computer and use it in GitHub Desktop.

Select an option

Save BastinRobin/bb5655d8355398fca1fcd07f1bd4bd90 to your computer and use it in GitHub Desktop.
List Transformation using Python
a = [
["id", "name", "age", "dept"],
[1, "Vishnu", 30, "PGDM"],
[2, "Suresh", 30, "PGDM"],
[3, "Akash", 30, "MBA"],
[4, "Nabin", 30, "BBA"],
[5, "Akshita", 30, "BCA"],
[6, "Margo", 30, "MCA"],
[7, "Robin", 30, "BSc"]
]
# loop the array a
headers = a.pop(0)
result = []
for i in range(len(a)):
temp = {}
for j, name in enumerate(headers):
temp[name] = a[i][j]
result.append(temp)
for i in range(len(result)):
print result[i]['id'],result[i]['name'],result[i]['age'],result[i]['dept']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment