-2

Here I'm trying to get the last m2id to print it into console.

[{
    "m2id":"865199733949071370",
    "author":{
      "id":"862323352869797948"
    }
  },
  {
    "m2id":"865199658103078925",
    "author":{
      "id":"751742911682445312"
    }
}]

And here's the code I wrote for it. (r.json being the json above):

data = r.json()
for id in data:
    id3 = id["id"][-1]
    print(id3)

Running the code gave me the last number of the first m2id, Which is not what I want.

Edit: data[-1]["id"] Worked. Thanks to everyone!

Chaotix
  • 11
  • 2

1 Answers1

-2

You can try this x = [{ "m2id":"865199733949071370", "author":{ "id":"862323352869797948" } }, { "m2id":"865199658103078925", "author":{ "id":"751742911682445312" } }]

print(x[len(x)-1]["m2id"])

Output 865199658103078925