#๐Ÿ”’ How do i use the second thing from a dict list?

76 messages ยท Page 1 of 1 (latest)

sand totem
#

I need it to determine placement in a calculetour.

kind fableBOT
#

@sand totem

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

#

Hey @elder fossil!

Please edit your message to use a code block

```py
print('Hello, world!')
```

This will result in the following:

print('Hello, world!')```
idle wraith
#

OP's data is only 1 dict. Not a list of dicts

sand totem
#

no i want to use the second data to find the first

idle wraith
#

!rule ai is not why they're here for.

kind fableBOT
#

10. Do not copy and paste answers from ChatGPT or similar AI tools.

idle wraith
#

that would be confusing with all of those 0

sand totem
#

0 is supposed to mean no button

#

essentially you can buy buttons

#

that's why there are empty buttons

idle wraith
#

ok so you now have a different way of finding "equal"

sand totem
#

that's exactly - what i am trying

idle wraith
#

You'll have to loop over the items and find it

sand totem
#

cuase this is a game

idle wraith
sand totem
#

yup

idle wraith
#

You could put it in a sqlite database

#

And then do a SQL ORM select where value clause

sand totem
#

is that a libary?

idle wraith
#

!d sqlite3

kind fableBOT
#

Source code: Lib/sqlite3/

SQLite is a C library that provides a lightweight disk-based database that doesnโ€™t require a separate server process and allows accessing the database using a nonstandard variant of the SQL query language. Some applications can use SQLite for internal data storage. Itโ€™s also possible to prototype an application using SQLite and then port the code to a larger database such as PostgreSQL or Oracle.

The sqlite3 module was written by Gerhard Hรคring. It provides an SQL interface compliant with the DB-API 2.0 specification described by PEP 249, and requires SQLite 3.15.2 or newer...

idle wraith
#

Its built-in to python

#

!pip sqlalchemy is handy library that makes queries easier to maintain and such

kind fableBOT
idle wraith
#

But tbh, its a bit of an overkill just for 1 button_placement. But if your game is going to grow and begins to hold more data, then the sqlite database makes a bit more sense

sand totem
idle wraith
#

Otherwise, you can try and search on youtube

#

Are you a Python programmer who loves Data? This is your lucky video! Hit play as we dive into the world of SQLite in Python. We'll cover connecting & creating databases, cursors, different ways to execute queries, the secrets of dodging SQL Injection Attacks, and more! So buckle up, grab your coding gear, and let's get this party started!

Fin...

โ–ถ Play video
loud iron
acoustic vessel
sand totem
#

Equal is one

#

I added as first for testing

loud iron
sand totem
sand totem
#

let me test it out

#

if it words than I will end this thread if not than no

loud iron
#

and why are you using multiple dictionaries instead of lists of objects (or you can use lists/tuples as grouped data)

sand totem
#

cause I am retrying python after 2 years and the most coding I ever did was a simple weight calculator

#

in other words I am dumb

loud iron
#

Yeah since the goal is learning python i would suggest practice with slightly better practices

#

List of dicts is useful as easy objects:
buttons = [{"x": 129, "y": 329...},...]

#

I would recommend it if you already know lists and dicts but havent learnt objects

sand totem
#

boys thank you

sand totem
#

It's done

pure yoke
slender dust
# sand totem

show the whole code that is using those dictionaries tuples and the list
because from the little code that you showed so far it doesn't even looks like you are using the dictionaries tuples and the list for anything useful, and depending on how you're going to use the data would inform how the data would be better structured

pure yoke
#

i also thought they were {} at first, even then that would be a set tho

slender dust
# pure yoke they are tuples

you're right, i was just stuck thinking of dictionaries after just reading through the whole thread from the top down as it mostly is about the dictionaries that OP originally used in their code

sand totem
#

@kind fable

#

I essentially have to use replit cause my school require to usethe laptops they give us

#

and you can't install anything unless its from microsoft store (for exe file)

#

including pygame

#

and this is group work

#

so my partners needs to see this

slender dust
slender dust
#

@sand totem about your code:

  • you don't have to pre-populate your dictionaries like that when you initialize the dictionary, and you could probably do with just using lists instead in many scenarios
  • the two loops in the beginning could be combined into one loop and eliminate a lot of code duplication
  • creating the buttons would probably be better done in a loop to not need to repeat as much code and put that data into dictionaries instead
  • the code could be simplified and shortened by reusing more code by encapsulating more of it in functions
  • the code would greatly benefit from using classes to define your own data type to hold the data, but i don't know if that is something you have learned yet
#

and it would have been easier to read the code as text instead of a lot of screenshots, and as this is probably more code than would fit in one message here on discord, using this discord servers paste service is probably the best solution
the link to oaste service and the instructions about how to refer to your posted code here on discord will follow

#

!paste

kind fableBOT
#
Pasting large amounts of code

If your code is too long to fit in a codeblock in Discord, you can paste your code here:
https://paste.pythondiscord.com/

After pasting your code, save it by clicking the Paste! button in the bottom left, or by pressing CTRL + S. After doing that, you will be navigated to the new paste's page. Copy the URL and post it here so others can see it.

slender dust
#

using text instead of screenshots doesn't only simplifying reading the code for others but it also makes it easier for people to provide help by not having to retype chunks of your code here in the chat to suggest changes or comment on parts of your code, increasing the chances of you receiving help here

kind fableBOT
#
Python help channel closed for inactivity

This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.