Python multidimensional array

Asked

Viewed 132 times

2

I have a series of data that I would like to organize by title, example;

movies = [
   'movie': [
      'legenda' [
         'dub', 'leg', 'nac'
       ],
      'time': [
        1, 2, 3, 4, 5
      ]
   ]
   ....
]

I tried with dict() with list() and I haven’t gotten any results yet.

 for movie in soup.find_all(class_="filme"):
    movies.update({'title', movie.h4.a.get_text()})
    for legend in movie.select(".movie-info .leg img"):
        movies.update({'leg', legend.get('alt')})

This way it will only update what I have, do not know how to create this multidimensional with python (yet)

1 answer

1

You are trying to define a Dict as a list. Try setting Dict in parentheses instead { }, in this way:

movies = {
   'movie': {
      'legenda': ['dub', 'leg', 'nac'],
      'time': [1, 2, 3, 4, 5]
   }
   ....
}

A Dict, unlike a list, is always a group of combinations between a key (e.g.: legenda) and a value (ex: ['dub', 'leg', 'nac'])

Browser other questions tagged

You are not signed in. Login or sign up in order to post.