Home > OS >  JikanPy sorting output to just urls
JikanPy sorting output to just urls

Time:08-01

I'm using JikanPy to get the top 50 anime and the code prints a list but it is very unorganized. How do I only get the things i want from the dictionary/list. I only want the urls, so how could I only get the urls from the list/dictionary? I've tried the subtypes like 'tv' but that still is unorganized I only want the urls or just the names of the animes and put them into a big list. I've looked through the documentation of the module/api and I couldn't find any way to sort the output in the way I wanted.

from jikanpy import Jikan    # imports the module
jikan = Jikan()              
a = jikan.top(type='anime')  # creates the dictionary
b = []                       # makes the variable 'b' a list
b.append(a)                  #converts the dictionary into a list
print(b)                     # prints it

CodePudding user response:

I don't understand the jikanpy module. So, as a wid guess, you are probably looking for something like this:

from jikanpy import Jikan    
jikan = Jikan()              
top=jikan.top(type='anime')['top']
url=[i['url'] for i in top]
#printing urls:
for i in url:
    print(i)

P.S.1 Your statement b.append(a) does not convert a into a list. It appends a to the list b.

P.S.2 As i mentioned i don't fully understand the jikanpy module, so there may be a better way.

  • Related