Search code examples
pythonlistfilekeygoogle-colaboratory

How to access each element in object in google.colab?


I uploaded a file in googl colab and I tried to get the name of the file

This is a result when I print upload.keys():

dict_keys(['SSE.csv', 'SSE_origin.csv'])

I tried to access each element of object. I only find this solution.

from google.colab import files

uploaded = files.upload()

for name in uploaded.keys():
    print(name)

Is there any other solution like indexing?


Solution

  • The problem is that you have a dict_keys object, not a list. To use it as a list you have to convert it:

    list(uploaded.keys())
    

    Now you can access each element by indexing