Reputation: 99
I have a json file with 6 "coins" to each user (which the user can change), I am trying to get this data saved in the json file and match it with another 6 coin pattern in order to check how many matches are made in total. The json file format is:
{"331971067788787733": [":Helicopter:", ":Skateboard1:", ":swords:", ":mace:", ":Helicopter:", ":Skateboard1:"]}
With each "coin" being a discord emoji.
The code for the user to save it is:
@client.command()
async def Shibaku1(ctx, coin1, coin2, coin3, coin4, coin5, coin6):
with open('Shibaku1.json', 'r') as f:
coins_data = json.load(f)
coins_data[str(ctx.author.id)] = (coin1, coin2, coin3, coin4, coin5, coin6)
with open('Shibaku1.json', 'w') as f:
json.dump(coins_data, f)
How do I extract the string value of each coin from the json file with the users 6 coins? in order to compare them with the main pattern to find the number of matches.
Upvotes: 1
Views: 243
Reputation: 559
So u can use for loop i list to compare the values, example given below :
for coin in coins_data[str(ctx.author.id)]:
if coin != new_coin:
#do smthing
Upvotes: 1