title: How can I create a dictionary from a list where the keys are the indexes and the values are the actual elements of the list one by one?
body: <p>I need to initialize a dictionary to start a clustering model of the elements I have in a list, and when I'll do the clusters I will merge the elements by their indices, but then I need to display the strings that I have in the list. So I thought about doing a dictionary and merge the values every time I cluster them. </p>
  
  <p>So let's say that I have the following list: </p>
  
  <pre><code>fileList = ["doc1", "doc2", "doc3", "doc4", "doc5"]
  </code></pre>
  
  <p>My idea is to create a dictionary out of them with indices as keys and the strings as values:</p>
  
  <pre><code>fileDict = {0: ["doc1"], 1: ["doc2"], 2: ["doc3"], 3: ["doc4"], 4: ["doc5"]}
  </code></pre>
  
  <p>And then after the clustering process, I can change the names of the keys and print:</p>
  
  <pre><code>clustersDict = {1: ["doc1", "doc2", "doc3"], 2: ["doc4", "doc5"]}
  </code></pre>
  
  <p>Now, what I tried was this:</p>
  
  <pre><code> clustersDict = dict.fromkeys([i for i in range(len(listFiles)), name for name in listFiles]) 
  </code></pre>
  
  <p>And the problem is that to every key it attaches the whole list of files, not just one, I tried with the index I but it obviously says that it's not defined, and I don't really know how to move on since I'm pretty new to Python. </p>
  
  <p>Thank you!</p>