L
L
Lol Likovic2020-07-20 17:34:32
Python
Lol Likovic, 2020-07-20 17:34:32

How to show two different values ​​from two different dictionaries (in a discord bot)?

in general, I do the code:

import discord
from discord.ext import commands
from discord.ext import tasks
from time import time, localtime

user_counter = {}

user_kolvo = {}


msg = 'Статистика:\n'


client = commands.Bot( command_prefix = '-')



@tasks.loop(seconds=20)
async def timer_notify():
    await client.wait_until_ready()
    cur_time = localtime(time())
    my_channel = client.get_channel(734611425368211457)
    for user_id,counter in user_counter.items():
        user = client.get_user(user_id)
        global msg
        msg = msg+' >> ' + user.name + ': ' + str(counter) + ' подходов' + ' | ' + str(kolvo) + ' раз' + '\n'
    await my_channel.send(msg)
    msg = 'Статистика:\n'

And I ran into a problem that in the line
msg = msg+' >> ' + user.name + ': ' + str(counter) + ' подходов' + ' | ' + str(user_kolvo.values()) + ' раз' + '\n'

I can't show both str(counter) and str(kolvo) because I'm only working in one dictionary (I can't write
for user_id,counter in user_counter.items() and user_id,kolvo in user_kolvo.items()

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
shurshur, 2020-07-20
@Lolik666

for user_id,counter in user_counter.items():
  ...
  msg += "Ой, а вот у **%s** целых %d подходов %d раз" % (user.name, counter, user_kolvo[user_id])

Or even like this:
for user_id in user_counter:
  ...
  msg += "Ой, а вот у **%s** целых %d подходов %d раз" % (user.name, user_counter[user_id], user_kolvo[user_id])

In general, if several indicators are stored for the user at once, then it may be time to store not numbers in several arrays, but entire dictionaries in one:
user_data[user_id] = { "counter": число, "quantity": число, "birthday": "32.05.1700" }
...
for user_id in user_data:
  msg += "Ой, а вот у **%s** целых %d подходов %d раз" % (user.name, user_data[user_id]["counter"], user_data[user_id]["quantity"])

S
soremix, 2020-07-20
@SoreMix

So what needs to be done? Why can't you use values ​​from another dictionary? Why can't two cycles be done? it's unclear

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question