Searching ReplDB

Question:
When searching a ReplDB with dictionaries inside of dictionaries, the results display as a list by letter instead of by word (I hope that makes sense). I was able to create a minimal Repl that reproduces my problem so that you don’t have to debug a large amount of code.

How can I get my expected result? I find this data structure for the DB very useful for my program but I can’t figure out why it puts each letter as its own item in the list.

Expected result of program:
['joe', 'steve']
Actual result:
['j', 'o', 'e', 's', 't', 'e', 'v', 'e']

Repl link:
https://replit.com/@CoderElijah/ReplDB-Problems#main.py (I think you have to fork it for it to work since it’s a DB.)

from replit import db
db["test"] = {}
db["test"].update({"1":{"name":"joe"}, "2":{"name":"steve"}})
def search(numbers:list):
  results = []
  for result in numbers:
    results += db["test"][result]["name"]
  return results
print(search(["1","2"]))
4 Likes

That would probably break it. .append is how to add to a list in python, not += (try’s to treat list as a string afaik)

5 Likes

I always make such stupid mistakes. That fixed it. It also explains some problems I’ve had in other programs…
Thank you for your help!

4 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.