0

Here d is a list of lists of lists with structure like this

[
    [

        [vocab[START], vocab["image1"], vocab["caption1"], vocab[END]],
        [vocab[START], vocab["image1"], vocab["caption2"], vocab[END]],
        ...
    ],
    ...
]

I don't know the dimensions already therefore I have problem in initializing, keeping an upper limit I could have used the xrange function like this

d=[[[[] for k in xrange(50)] for j in xrange(10)] for i in xrange(8769)]

but I'm working in Python3 and xrange is depreciated. The code goes like this

for i in range (len(t)):

  for j in range (len(t[i])):

   d[i][j][0]=vocab[START]

   for k in range(len(t[i][j])):

   if t[i][j][k] not in list(vocab.keys()):
    d[i][j][k+1]=vocab[UNK]
   else:
    d[i][j][k+1]=vocab[t[i][j][k]]

Any help on this is appreciated.

sirandy
  • 1,834
  • 5
  • 27
  • 32
  • 3
    what about `d=[[[[] for k in range(50)] for j in range(10)] for i in range(8769)]` ? `xrange` now is `range`. – Jean-François Fabre Dec 17 '18 at 16:00
  • 1
    please don't mix issues like `xrange` is deprecated with your other problem. It's really unclear, please [edit] your question to cut to the chase. – Jean-François Fabre Dec 17 '18 at 16:01
  • It looks a lot like json except with lists instead of dicts, maybe the ideas [here](https://stackoverflow.com/questions/12507206/python-how-to-completely-traverse-a-complex-dictionary-of-unknown-depth) could be helpful? – Josh Friedlander Dec 17 '18 at 16:29
  • d=[[[[] for k in range(50)] for j in range(10)] for i in range(8769)] I did use it but like I said the dimensions are unknown and because of this I get a lot of empty lists[ ],which I do not want. I mentioned xrange because it's different in the fact that it creates lists lazily as per the demand unlike range in python3 – Ibtesam Ahmed Dec 17 '18 at 16:37
  • How and why do you want to initialize if you dont know dimensions? You can always `.append()` – Jasper Dec 17 '18 at 17:02
  • .append() gives me a 1D list which I do not want , I want a list in the 3D structure that I have mentioned above. – Ibtesam Ahmed Dec 18 '18 at 03:06

0 Answers0