Day 61: Building a dictionary is not working


I wanted to apply a bit a different solution to the challenge. However, it does not work and I get a very long error message. I would like to use a counting variable N as the key and a dictionary as the value. The dictionary should consist of the timestamp and the tweet.

def AddTweet():
  N += 1
  Tweet = input("Add your tweet\n> ")
  timestamp =
  key = N
  db[key] = {"Tweetcontent":Tweet,"Time":timestamp}

the db[key] prompts an error message. What I am doing wrong? Thank you in advance for your help!

I believe key should be a string, try db[str(key)] or key = str(N).

Thank you. I tried this and it not worked.

Have you printed out the value of N before you attempt to use it to access the db? I can’t see the rest of your code but I suspect that this might help.

1 Like

I found your Repl, forked it, and played around with the code to figure out what’s wrong. I had the right idea, just didn’t turn the right thing into a string. str(timestamp) fixes the issue. You can only store objects of the default Python data types in the Replit Database so the timestamp caused the error.

Perfect, highly appreciated!!!