#python-discussion

1 messages Β· Page 131 of 1

bleak moth
#
operations = {
  "add" : lambda a, b: a + b,
  "sub" : lambda a, b: a - b,
  "mul" : lambda a, b: a * b,
  "div" : lambda a, b: a / b
}
steady rain
#

the getitem syntax for lists and dicts are the same.

cobalt flax
#

k so .get seems redundant kinda

dry pike
#

it's not

cobalt flax
dry pike
#

it's used when you don't want to error if the key does not exist

steady rain
cosmic moat
#

Quick question I'm not sure how to Google... How can I exclude the first item in a list when using a function such as max?

dry pike
#

you can also specify a different default than None with a second argument to the method

charred python
#

ChainMap is the thing I was thinging of. Looks up values from 2 or more dicts.

from collections import ChainMap

users_by_id = dict((user.id, user) for user in users)
users_by_email = dict((user.email, user) for user in users)

user_lookup = ChainMap(users_by_id, users_by_email)

print(user_lookup[123]) # by id
print(user_lookup["bob@email.com"]) # by email
cosmic moat
#

Thank you!

steady rain
#

but you should only use dict.get if you have a plan for what you'd do if you get the default value. if a missing key means that the program is actually wrong, you should just let yourself get the key error.

cobalt flax
#

what does lambda mean though

#

kinda weird name

steady rain
bleak moth
dry pike
#

in fact it's a syntax error

#
>>> lambda (a, b): a + b
  File "<python-input-0>", line 1
    lambda (a, b): a + b
           ^^^^^^
SyntaxError: Lambda expression parameters cannot be parenthesized
bleak moth
tame hinge
cobalt flax
dry pike
#

it's only for defining functions as expressions in Python

cobalt flax
#

ok

bleak moth
cobalt flax
#

so defining functions as expressions

dry pike
#

because def is a statement

tame hinge
bleak moth
#

So basically, if it expects a function, and you only need it to evaluate an expression, you can prefix the expression with lambda, and a capture group (the parameters to that function) and what expression you want it to do with those parameters

dry pike
#

never heard "capture group" in the context of functions

#

I know that capture group is a concept from regex

bleak moth
# dry pike what? no

I mean, you keep saying use functions as expressions and it's more accurately the inverse. Where a function object is expected, you can use a lambda to just use an expression instead of creating a function and then putting the name of the function without parentheses or parameters in its place.

cobalt flax
#

so can i do something like ```py
arbitraryOperations = lambda a, b, c: a * b + c

print(arbitraryOperations(5, 3, 1))


` output == 16`
#

?

dry pike
cobalt flax
bleak moth
dry pike
#

well, this isn't C++

tall vector
#

and closures != lambdas

cobalt flax
bleak moth
cobalt flax
#

this seems awesome actually

bleak moth
dry pike
cobalt flax
#

ohhhhhh this is interesting so using .get() also acts as a bool sometimes

#

like if i did

dry pike
#

there is no "capturing" going on with the parameters of a lambda

#

it doesn't make sense in Python

cobalt flax
#
if codeWordsForChristmasMission.get("THE RED CLAW"):
  print("he's here")
else:
  print("WHERE IS SANTA")
dry pike
#

None is falsy

cobalt flax
#

since "THE RED CLAW" is a key in my dictionary

steel whale
#

is there something like conhost but on linux?

dry pike
#

you will also run the else if the value associated with that key is falsy, such as empty string, list, 0, etc

cobalt flax
#

i dont have to do codeWordsForChristmasMission.get("THE RED CLAW") != None

#

which is cool

#

cuz like if it returns anything thats acting as "True"

dry pike
spice hill
tall vector
visual juniper
#

thats how they make you do import typing

cobalt flax
#

seems more readable

spice hill
cobalt flax
#

dont say "more correct" that makes me feel wrong

#

and i aint wrong im just flawed

charred python
indigo veldt
#

hello

dry pike
cobalt flax
dry pike
#

can you stop please

robust ledge
#

It's fun that three different if statements have been shown with three different logical outcomes. The "correct" is the one that does what is expected. Nothing more than that.

cobalt flax
#

right sorry for pulling your leg

#

why is it flawed exactly?

dry pike
#

because you are relying on the value associated with that key to check if the key exists, when using .get() like that

cobalt flax
#

ah yeah i guess that'd be less efficient than just checking if the key is there in the first place

#

cutting the middle man

dry pike
#

it's not about efficiency, they have different outcomes

dry pike
#

I have already

visual juniper
cobalt flax
#

wait ok im getting lost here
if checking if a key in a list returns anything

#

vs

dry pike
#
d = {"a": 0}

if d.get("a"):
    print(1)
if "a" in d:
    print(2)

2

cobalt flax
#

if checking if a key in a list is there at all

rugged barn
#

Good timezone

cobalt flax
rugged barn
#

Do you now

visual juniper
# cobalt flax if checking if a key in a list is there at all

.get will try to find a value for that key in a dictionary , if a value is found , it will return the value , if not , it will return None
whereas in just checks if the key is present in the dictionary at all , it doesnt care about the value of that key

cobalt flax
#

a is there!!!

bronze dragon
cobalt flax
#

a is still with us!!!

dry pike
#

because d.get("a") return the value associated with "a"

#

which is 0, which is falsy

cobalt flax
#

falsy?

#

thats different from false?

dry pike
#

treated as false in boolean contexts

visual juniper
cobalt flax
#

thought you were being playful but yeah feels proper to make that distinction

cobalt flax
#

now that is interesting

cobalt flax
dry pike
#
vals = ["", [], {}, (), 0, 0.0]
for val in vals;
    print(bool(val))

False
False
False
False
False
False

cobalt flax
#

Thought it would still return true to be honest

dry pike
#

I gotta go now

cobalt flax
cobalt flax
dry pike
#

and then there is truthy

#

"abc", [1, 2, 3], 1, -1, 4 etc

cobalt flax
#

oh well yeah

dry pike
#

bye

quartz fulcrum
#

i read about truthy and falsy..but i forgot

cobalt flax
#

bye!

oblique spindle
#

also None is falsy but something is false and something is None are very different

cosmic moat
#

Excuse me, it's me again. It says the name of my list of lists is not defined. How can I define it? When I try to Google "how to declare lists" I only find ways to declare a list with elements that are already known, but I need to add elements after I define it

cobalt flax
#

all of these values in different data types are falsys

#

they are pieces of data but they are read in terms of booleans as false

oblique spindle
cobalt flax
#

so a falsy is just false in the perspective of mr boolean

visual juniper
quartz fulcrum
#

oh.so if i write return []
then it will return false?

oblique spindle
cobalt flax
#

oh. wait huh

quartz fulcrum
oblique spindle
#

basically wherever python expects a bool [] is considered as false

cobalt flax
#

oh

bronze dragon
charred python
#

if can only ever be true or false. So it does the impliciat conversion to bool. But return can return any value so it does not do any conversion. It returns the real value.

oblique spindle
#

if statements , while statements etc

cobalt flax
#

see wizard we're both learning

dry pike
visual juniper
charred python
quartz fulcrum
cobalt flax
#
stringFalsy = ""

if stringFalsy:
    print("yeah")
else:
    print("noh")
#

this prints noh

visual juniper
cobalt flax
#

ohhhhhhhhhhhhhhh ok so yeah its for if statements it seems

cobalt flax
#

IT NEVER WORKED BUT I HAD TO PUT IT IN PARENTHESES??

bronze dragon
#

! isn't valid Python though

cobalt flax
#

thoe worms

autumn forge
cobalt flax
visual juniper
#

oh , yeah , my bad , you would use the not keyword

#

C++ habits

cobalt flax
#

grah those worms x2

quartz fulcrum
charred python
quartz fulcrum
#

can you explain

visual juniper
autumn forge
cobalt flax
#

yeah ! except behind a = is invalid........

cobalt flax
#

ahah ok k ok ok ok

visual juniper
#

yeah , thats not valid python

visual juniper
cerulean ravine
#

Hmm, i want to record information at runtime about code objects, but I don't know how to uniquely tie them back to source code. This is a problem:

a, b = (lambda x: 1), (lambda x: 2)

This is two code objects with the same file name and line number πŸ™

cobalt flax
#

treat "!=" as " is not "

visual juniper
#

well......

cobalt flax
#

its the direct opposite of ==

charred python
#

Fun fact, not also does impliciy bool conversions since it's meant to negate bools. So

my_list = []
print(not my_list) # prints True
return my_list # returns [] (not True/False)
lapis sedge
#

erm guys I learnt about pyhton in GCSE but only the basics and I'm trying to program a model that can just give me values on a quadratic graph but i've got this error I've never seen before and its basically saying that I have an "Invalid literal for int() with base 10" I dont know what that means

#

Its been like ages since I've done coding dont slime me

visual juniper
worn moth
#

not not foo is bool(foo)

pastel sluice
cobalt flax
lapis sedge
#

Okay how do you show code

cobalt flax
#

not python syntax grah im bad at explaining

pastel sluice
edgy krakenBOT
#
Formatting code on Discord

Here's how to format Python code on Discord:

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

These are backticks, not quotes. Check this out if you can't find the backtick key.

For long code samples, you can use our pastebin.

visual juniper
#

!paste or this if the code is too big for discord

edgy krakenBOT
#
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.

cobalt flax
quartz fulcrum
ember quest
#

afaik it access dunder not

#

and doesnt coerce

#

i think python doesnt have coercion in general

lapis sedge
#
Count = 0
Horizontal = 0
HorizontalMultiplier1 = input(int("What is the exponent multiplier?"))
HorizontalMultiplier2 = input(int("What is the second x coefficient multiplier?"))
Y_intercept = input(int("What is the Y-Intercept value?"))
Height = HorizontalMultiplier1*Horizontal^2 + HorizontalMultiplier2*Horizontal + Y_intercept
print("Horizontal Value (x axis) is at position: " + str(Horizontal))
print("Vertical Value (Y axis) is " + str(Height) + " at x position: " + str(Horizontal))
for i in range(0,20):
    Horizontal = Horizontal + 0.5
    print("--------------------------------------- Value Number: " + str(Count) + " ---------------------------------------")
    print("Horizontal Value (x axis) is at position: " + str(Horizontal))
    print("Vertical Value (Y axis) is " + str(Height) + " at x position: " + str(Horizontal))
    print("----------------------------------------------------------------------------------------------------------------")
edgy krakenBOT
#

Hey @lapis sedge!

Please edit your message to use a code block

Make sure you put your code on a new line following py. There must not be any spaces after py.

Here is an example of how it should look:
```py
print('Hello, world!')
```

This will result in the following:

print('Hello, world!')```
charred python
#

It's close enough for someone learning about why if statements care about Truthyness

#

conversion, coersion, indoctrination, whatever πŸ™‚

ember quest
#

im just asking if im horribly mistaken

quartz fulcrum
#
hi = 0
if hi == False:
    print('hello')
lapis sedge
#

Dont shoot me i'm SO buns but I have to make sure I don't get rusty its been 6 months

visual juniper
#

its more like an "operator" i would say

quartz fulcrum
#

is this code correct?

visual juniper
ember quest
#

i cant find a clear thing on how dunder not is defined for lists

quartz fulcrum
#

i am on mobile

cerulean ravine
ember quest
visual juniper
oblique spindle
cerulean ravine
ember quest
#

but i dont know what you wish for it to achieve

spice hill
#

I would describe implicit conversion to bool as the same kind of conversion that JavaScript does when you add a number and a string

visual juniper
ember quest
quartz fulcrum
cobalt flax
#

oh you cant index a dictionary with a number

#

ya gotta use the key

ember quest
#

(i havent tried terribly hard to dig into it)

cobalt flax
#

interestingggggggggggggg

cerulean ravine
visual juniper
ember quest
fallow kiln
#

Is there a designated place to discuss computer vision?

quartz fulcrum
cerulean ravine
ember quest
#

last time i tried to dig in into the source code i couldnt find the file that defines them rip

cosmic moat
#

Excuse me, me again. Am I allowed to do this?
table=[[" "]*(int)maxx]*(int)maxy

#

The error message just says "invalid syntax"

cerulean ravine
cerulean ravine
paper plaza
#

Thats c style typecast

cosmic moat
#

I can't figure out if it is or not, but it said it wasn't

cosmic moat
#

Thank you!

quartz fulcrum
#

in which library Measures of central tendency formulas exist?

unborn lagoon
edgy krakenBOT
#

Added in version 3.4.

Source code: Lib/statistics.py

This module provides functions for calculating mathematical statistics of numeric (Real-valued) data...

cerulean ravine
#

@cosmic moat but also, you will find that 2D board shares data between cells, so you need to make it differently.

shrewd pine
#

why C cast not supported in C Python :'(

robust ledge
cosmic moat
#

What does it do? I will investigate as well

spice hill
edgy krakenBOT
brave nexus
#

What is the best free python course and resource

shrewd pine
edgy krakenBOT
quartz fulcrum
#

is it possible that bot will import and run libraries in the server here

cosmic moat
#

Oh, I don't need to append, I'll be working with individual cells

spice hill
cerulean ravine
visual juniper
spice hill
brave nexus
shrewd pine
edgy krakenBOT
cosmic moat
#

I see...

visual juniper
spice hill
unborn lagoon
edgy krakenBOT
#
Resources

The Resources page on our website contains a list of hand-selected learning resources that we regularly recommend to both beginners and experts.

steel whale
cosmic moat
#

Do I need to make it something like blah[0][0][0]= 'oh no'?

shrewd pine
edgy krakenBOT
cobalt flax
#
codeWordsForChristmasMission = {
    "THE RED CLAW" : "Santa Claus",
    "LITTLE LAMB" : "Present Delta",
    "GRAZE VICTIM" : "Christmas Tree"
}

flashCards = codeWordsForChristmasMission.items()

print("alright agent elf, here are the necessary codewords")
for codeWord, definition in flashCards:
    print(f"{codeWord} means {definition}")
#

rad.

shrewd pine
cobalt flax
#

dictionaries are easyyyyyyyyyy

shrewd pine
#

(because you can't mutate strings)

cosmic moat
#

That makes sense!

pulsar dragon
#

Hello, I want a Python code that calculates a countdown to New Year's and sends "Merry Christmas" messages.

paper plaza
cobalt flax
#

im sorry i dont know how to answer that question

paper plaza
#

Rip

charred python
pulsar dragon
unborn lagoon
bleak marsh
paper plaza
cobalt flax
robust ledge
cerulean ravine
charred python
#

I don't even need to try. It comes naturally.

cerulean ravine
quartz fulcrum
#

i got afraid for a sec why everyone's name is followed by 00:00

but then i realised its 12:00 am here

charred tusk
edgy krakenBOT
#

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

pulsar dragon
steady rain
bleak marsh
#

but claude can teach him better actually i think

charred python
charred tusk
pulsar dragon
cosmic moat
#

Does print() normally add a return carriage after it runs? Can I make it not do that?

cerulean ravine
visual juniper
shrewd pine
cobalt flax
charred python
#

I appreciated it but I can't emoji.

cobalt flax
#

uhh so like when does this timer start?

visual juniper
pulsar dragon
cobalt flax
robust ledge
# pulsar dragon How so?

That's what we're asking you. We help people learn python here. So where have you started with this project of yours?

cobalt flax
#

do you want this timer to be usable or just like a short exercise

bleak marsh
cobalt flax
#

when does the timer start

#

is it synced with your local time?

pulsar dragon
charred python
#

We don't teach as in lead you, but we'll happy answer questions when you try something and need help getting past it.

cobalt flax
#

when does it send christmas messages? right at 12:00 am on christmas day?

languid monolith
#

Code, google, ask questions, learn etc. no one had time to hold your hand

cobalt flax
#

how often does it send christmas messages and when does it stop?

bleak marsh
shrewd pine
cerulean ravine
robust ledge
cerulean ravine
bleak marsh
#

ok np bro

autumn forge
cobalt flax
winter pewter
#

Guys when I run code in vscode why doesn’t it appear in output

cobalt flax
#

i know i will at some point but it feels so satisfying to have some random person who just helps people then help me

quartz fulcrum
cobalt flax
#

cuz like we're both satisfied in this situation

ember quest
steady rain
bleak marsh
pulsar dragon
cobalt flax
steady rain
winter pewter
bleak marsh
winter pewter
cobalt flax
paper plaza
#

Do you have python installed

steady rain
edgy krakenBOT
#
Formatting code on Discord

Here's how to format Python code on Discord:

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

These are backticks, not quotes. Check this out if you can't find the backtick key.

For long code samples, you can use our pastebin.

charred python
cobalt flax
cobalt flax
#

you send it here as a message

ember quest
#

oh if you are checking output tab its not there

cobalt flax
#

unless its too long and in which case.. !paste

#

oh damn

pulsar dragon
winter pewter
#

Il just copy and paste it, it’s only like 10 lines from a tutorial

cobalt flax
#

the project goal

ember quest
cobalt flax
#

because your explanation was a bit vague

ember quest
#

altho i do ask it for code reviews and to bounce ideas off it

pulsar dragon
shrewd pine
cobalt flax
pulsar dragon
#

e.g.

bleak marsh
cobalt flax
#

do you want help with a specific program you want to make

bleak marsh
#

possible

ember quest
#

sure

#

im not a dev i dont do dev work

inland thorn
#

hey guys im new to python and i wanted to ask how like im supposed to deal with OOP

like i come from C++ and im used to like having an object own its data and have functions do stuff to that data but it honestly almost feels inappropriate when there's no such thing as private members in python

do i just, do it anyways? use that _ prefix and call it a day? it just feels wrong

robust ledge
charred python
pulsar dragon
ember quest
#

i dont know if its discouraged

cobalt flax
pulsar dragon
#

Merry Christmas

winter pewter
#

is_student = False
print(f"are you a student? {is_student}")

if is_student:
print("you are a student")
else:
print("you aren't a student")
print("what are you then?")

edgy krakenBOT
#

Hey @winter pewter!

Please edit your message to use a code block

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

This will result in the following:

print('Hello, world!')```
cobalt flax
#

a private message through gmail?

#

again mate you're being a bit vague here

cobalt flax
#

do you want this timer to actually work in a real world or are you just doing an exercise

bleak marsh
pulsar dragon
muted rampart
paper plaza
robust ledge
steady rain
cobalt flax
bleak marsh
pulsar dragon
cobalt flax
#

uhhh wait lemme check smt

steady rain
cobalt flax
paper plaza
#

And operator overloading is the sams idea polymorphism is simpler no virtual...

ember quest
#

like a push notif?

cobalt flax
#

is this an email?

robust ledge
pulsar dragon
inland thorn
ember quest
#

im sure your os has a way to send notifs through the terminal

inland thorn
#

LOL

ember quest
#

so use that

muted rampart
#

Folks "private message" == "direct message" or DM

ember quest
#

the correct answer is to do this in bash

winter pewter
charred python
#

It is obvious this person isn't genuinly seeking python help.

bleak marsh
pulsar dragon
ember quest
muted rampart
cobalt flax
ember quest
#

no its just reddit terminology

winter pewter
pulsar dragon
paper plaza
muted rampart
winter pewter
cobalt flax
#

he could check if its new year by just seeing when the day and month of his device is "1/1" right?

ember quest
cobalt flax
robust ledge
shrewd pine
cobalt flax
#

we cant do anything with your idea until we get where it should be done

ember quest
#

@cobalt flax mate hows your learning going

charred python
cobalt flax
quartz fulcrum
pulsar dragon
cobalt flax
steady rain
shrewd pine
cobalt flax
robust ledge
inland thorn
pulsar dragon
cosmic moat
#

Alright, I've done it. Thank you for your help, everyone πŸ™‚

ember quest
#

i recommend learning fairly deeply about data structures from the start

steady rain
#

quintessential web developer mindset right here
savage
is this a stereotype?

ember quest
#

much helpful i think

bleak marsh
winter pewter
shrewd pine
ember quest
cobalt flax
cerulean ravine
shrewd pine
cobalt flax
#

i've seen those

ember quest
inland thorn
ember quest
#

in school i was just taught what they are (tuples are immutable etc), and their methods, which isnt very helpful information in the real world

winter pewter
#

Guys are there any other better ide’s than vs code (blue one) for a beginner

cobalt flax
ember quest
#

i keep forgetting how to add stuff to a set

#

but i know when and why to use them

cobalt flax
#

oh wait sorry

ember quest
inland thorn
shrewd pine
robust ledge
inland thorn
shrewd pine
#

wouldn't you?

cobalt flax
#

by the way quick question

#

i've been told that lists are faster

#

faster in what way? how faster?

shrewd pine
#

faster than?

ember quest
#

for what?

cobalt flax
winter pewter
ember quest
#

what?

inland thorn
# shrewd pine wouldn't you?

i have no idea how i would manipulate a struct through an opaque pointer given that the struct could literally be comprised of anything at any given moment lol

i should try that

muted rampart
#

That... lists are faster than lists?

cobalt flax
#

but i dont know like faster in what way

#

SORRY tuples

robust ledge
cobalt flax
ember quest
#

okay thats not true

cobalt flax
#

im a word jumble (i jumble words)

ember quest
visual juniper
#

fast in terms of what ? fast in terms of eating burritos ?

steady rain
ember quest
#

i think its because for tuples the values are stored near each other in memory

cerulean ravine
cobalt flax
#

ok k ok ok let me restate my question without jumbling words

muted rampart
visual juniper
#

xd

cobalt flax
#

How are tuples faster than other data structures, and in what way are they faster?

steady rain
shrewd pine
#

tuples might be faster, but probably not in a way that matters in most cases

ember quest
#

and i cant imagine it matters.

cerulean ravine
cobalt flax
inland thorn
cerulean ravine
halcyon ore
#

hi

inland thorn
#

alright guys thanks for ur help im gonna work on my project now and maybe come back here to chat soon

shrewd pine
cobalt flax
#

wait why do tuples exist if you can just have a list and.... not change it

cerulean ravine
ember quest
#

in any case even if they were faster it doesnt matter since you wouldnt use a tuple instead of a list

cobalt flax
muted rampart
ember quest
cerulean ravine
# cobalt flax expound

tuples can be elements of sets or keys in dictionaries. lists can't, bcause they can't be hashed.

robust ledge
ember quest
#

also its so you cant exactly change them

inland thorn
quartz fulcrum
#

I am currently navigating a career transition where my only viable options are remote work or further education. However, social media updates from peers are causing significant 'comparison trap' issues, making me feel pressured to pursue traditional roles that aren't right for me. I don't know if i study or do work from home jobs..btw the internships and jobs offered to me are not satisfactory

ember quest
#

if you make a tuple it makes it very clear that this is not a container you should fuck with much

quartz fulcrum
#

any suggestions?

cobalt flax
shrewd pine
cerulean ravine
cobalt flax
#

"The hash value is an integer that is used to quickly compare dictionary keys while looking at a dictionary."

charred python
muted rampart
#

Moral of the story is, tuples are immutable. Once you create one, you can't add new elements or remove any: you have to make a new one.

Some operations may be quicker with tuples for that reason, because the container can know its size without having to recompute it ever.

steady rain
# cobalt flax wait why do tuples exist if you can just have a list and.... not change it

there's a semantic difference. but it's kind of hard to explain.
usually, all the elements in a list are the same type, and the exact number of elements in the list usually can't be known just from looking at the code.
tuples, on the other hand: it's usually visibly apparent in the code exactly how many elements are in the tuple, and what types they are. and they often aren't the same type.

ember quest
cobalt flax
#

"compare" is such a broad term for me

cobalt flax
#

wait hold on thats just indexing a list by using []

robust ledge
ember quest
# cobalt flax oh

you literally can define a dunder hash that tells you how to hash them

cobalt flax
ember quest
#

its not exactly relevant

harsh anchor
cobalt flax
#

DOUBLE UNDER OH

velvet hull
#

i didmt code today

cobalt flax
#

__ bingo

muted rampart
#

That's always fun, making a custom __hash__ to use my own class as a dict key. πŸ™‚
Usually I just run tuple.__hash__(()) on some of the elements of that class.

Usually a AoC thing though.

cerulean ravine
inland thorn
# robust ledge You can bypass **anything** in any language if you try hard enough. And devs do....

yeah. its just in c++ its the norm to instead of putting up a sign, put up a fence. they'd have to jump over the fence to screw around. that's how i learnt to program, c++ was my first language and hell my only language (except c) until recently trying to learn python.

its just a lot looser than i learnt was acceptable when i was a impressionable beginner so. i mean its about the only way to do things in python so, i shall do it. just brand new to me

ember quest
shrewd pine
# cerulean ravine yes. does it matter?

the original comment made it seem like they are the same thing

an extra pointer indirection can matter, but in the context of python where basically everything is already a pointer indirection, not much

charred python
harsh anchor
cobalt flax
#

i can also do that in a list??

ember quest
#

it assigns a value to the whole object

shrewd pine
cobalt flax
#

just have a list and then list[number]

velvet hull
cobalt flax
ember quest
shrewd pine
#

it's not

cerulean ravine
inland thorn
# harsh anchor the way i learned to think about it is that python and c++ both have reflection ...

difficulty of use was never an issue for me. c++ is overwhelming not difficult, too much standard lib nonsense. at least for me. python also has a big stdlib which i don't like but at least it's not a complete train wreck. coding in python is a lot faster but i wouldn't say any easier. at the end of the day programming is programming, whether or not you have to deal with pointers and spam semicolons

robust ledge
cobalt flax
harsh anchor
cobalt flax
#

so let me define hash right now

#

a hash is an integer value designated to the whole data structure object in question

#

yay or nay?

ember quest
#

very much nay i think

cobalt flax
#

dang i've been nayed so much today

ember quest
#

i dont see why it has to be an integer

harsh anchor
#

it is an integer

cobalt flax
shrewd pine
harsh anchor
cobalt flax
#

like ok here here here ```py
myTuple = (1, 2, 3)

#

how would i "hash" this tuple

#

and what would it give me

harsh anchor
#

!d hash

edgy krakenBOT
#

hash(object, /)```
Return the hash value of the object (if it has one). Hash values are integers. They are used to quickly compare dictionary keys during a dictionary lookup. Numeric values that compare equal have the same hash value (even if they are of different types, as is the case for 1 and 1.0).

Note

For objects with custom [`__hash__()`](https://docs.python.org/3/reference/datamodel.html#object.__hash__) methods, note that [`hash()`](https://docs.python.org/3/library/functions.html#hash) truncates the return value based on the bit width of the host machine.
ember quest
#

you dont have to

visual juniper
# cobalt flax so let me define hash right now

hash (usually) is a function that takes in an arbitrary size of data and produce output string of fixed size
hash for different data should be different , otherwise we say the hashes "collide"

inland thorn
cobalt flax
visual juniper
shrewd pine
edgy krakenBOT
cobalt flax
#

and then "They are used to quickly compare dictionary keys during a dictionary lookup."

inland thorn
cobalt flax
#

that loses me

cerulean ravine
visual juniper
cobalt flax
#

is this storage size

shrewd pine
cerulean ravine
cerulean ravine
inland thorn
harsh anchor
cobalt flax
#

???????????????????????

bronze dragon
#

What were you expecting?

cobalt flax
#

so this is 100% some backend thing

ember quest
#

lmfao

cerulean ravine
cobalt flax
harsh anchor
cerulean ravine
#

(and that unequal values have likely unequal hashes)

cobalt flax
ember quest
#

wait until you see the SHA's

bronze dragon
faint solar
#

quick question, what kind of job can you get with python?

cerulean ravine
cobalt flax
cobalt flax
cerulean ravine
cerulean ravine
exotic flax
#

hi all

cobalt flax
#
Traceback (most recent call last):
  File "C:\Users\...\.py", line 13, in <module>
    print(hash( [1, 2] ))
          ~~~~^^^^^^^^^^
TypeError: unhashable type: 'list'
exotic flax
cobalt flax
#

ok i mean if a hash is just giving me an id for a tuple

exotic flax
#

Technically yes but very very low chance of that

cobalt flax
#

i guess it makes sense why it'd have to be an unchanging thing

exotic flax
#

or fo you mean __repr__

cerulean ravine
cobalt flax
#

a list is changing though so its more complicated

#

and thus cant be hashed

bronze dragon
cobalt flax
exotic flax
cerulean ravine
cobalt flax
#

now, ol' nedbat over here said that hashes of tuples arent meant to be understandable but are useful when checking if two tuples have the same hashes

velvet hull
#

do functions in other modules become methods or functions in a class becomes methods

harsh anchor
# cobalt flax and thus cant be hashed

at the risk of deepening the hole, you could hash lists, at the risk of loosing it in a dict. other languages let you do this. python chooses to not let you hash lists, though

cobalt flax
#

wouldnt the only cases in which tuples have identical hashes if the tuples themselves are identical?

harsh anchor
exotic flax
cerulean ravine
harsh anchor
tepid seal
#

Why do logging messages not appear in mu debug mode

cobalt flax
#

ok i think im understanding this a bit more

#

so how is hash collision a practical thing to use

bronze dragon
harsh anchor
cobalt flax
#

thought hashes were useful

cerulean ravine
harsh anchor
#

but you might be conflating hash collision with two things having the same hash

cerulean ravine
#

(like cars!)

shrewd pine
cobalt flax
exotic flax
# cobalt flax so how is hash collision a practical thing to use

hash collision is a very rare thing which typically requires a bery large amount of computing to do intentionally. The annual GDP of a small country worth of computing would be needed to do it intentionally to trick Bitcoin into accepting something. it happens in nature, you don't worry about it

cobalt flax
bronze dragon
shrewd pine
cerulean ravine
exotic flax
#

Hash collision is when two things mistakenly have the same hash.
hash comparison is the day to day thing you want to use

cobalt flax
#

using hashes?

exotic flax
cerulean ravine
#

it's easy in Python to make two tuples with the same hash.

bronze dragon
cobalt flax
#

?

bronze dragon
#

the value can be whatever you want

#

the idea of a dict is to let you quickly look up values by their key. as a fact of implementation, it uses hashes to achieve this efficiently.

cobalt flax
#

the dictionary is referring to the tuple variable by the tuple's hash?

harsh anchor
#

i think you should get more familiar with dictionaries before learning how they work internally

cobalt flax
#

yay or nay?

shrewd pine
inland thorn
#

i have another question

if there's no private members then why would i need setters and getters?

like i would imagine there's a place for them, but where? thread safety? like if i have just a game object and this object has velocity and stuff do i have a setter and getter for all of its member variables even if i can just tap into them directly and set them? that just seems like a waste of code?

i understand why you would need the illusion of private members at all, 100% but like, when it comes to stuff that is accessible, i would usually just make everything private and give it a setter/getter in c++

bronze dragon
cobalt flax
harsh anchor
#

sunk-cost fallacy suggest that you should stop

cobalt flax
#

I probably wont use this knowledge much as the dictionary is using it not me BUT

unborn lagoon
harsh anchor
mossy sigil
#

hello everyone

cobalt flax
#

i appreciate the help so thank you very very very super ultra duper very much my friend

shrewd pine
exotic flax
#

think of it like this: a box has a fixed shape. Cloth does not. a cloth bag that fits 2 boxes now might fit two differently shaped boxes later, or might have more than one box, so you can't compare two cloth bags by the shape. you can compare two boxes by the shape.

cloth is a list.
box is a tuple, an integer, a string, or some such data type that can be compared.

the hash is like if you took the shape of an object & made a shitty (but consistently shitty) drawing of it. a special machine can look at the drawing and understand kiinda what the original might look like, but you can only look at it and scratch your head as it is. On the other hand, you can compare two drawings just fine.

inland thorn
#

alright all my questions have been answered

thanks all, gonna go work now

exotic flax
exotic flax
#

a real cryptosecure algorithm would need a very very specific dataset to maximize chance of collision

cobalt flax
#

great explanation

cerulean ravine
exotic flax
exotic flax
cerulean ravine
#

i think it's important to distinguish between cryptographic hashing and the kinds of hashes Python uses for data.

exotic flax
#

dude i think you're not reading what i said... yes python uses a weak algorithm that's what i said, that doesn't impact the fact that you can use a more secure one if you want

cerulean ravine
exotic flax
#

hm well that's a different story then yes

cerulean ravine
#

and data collisions are really really easy. If you build a web service that accepts stringified tuples, and stores them in a set as actual tuples, it's easy for me to attack you.

cobalt flax
#

"TypeError: dict.get() takes no keyword arguments"

wh, YEAH YOU DO!!!

#

context:

#
while True:
    missionInfo = input("What will you be expecting on the mission, agent elf? ")
    print(codeWordsForChristmasMission.get(missionInfo, __default="Huh?"))

# codeWordsForChristmasMission is a dictionary defined previously
dull dune
#

in that case, you cannot pass __default as a kwarg

cobalt flax
#

i trust my computer...

unborn lagoon
cobalt flax
dull dune
#

see the definition here:

harsh anchor
#

🀨

exotic flax
#

lol ive never seen it before

cobalt flax
dull dune
#

that trailing / makes it positional args only

cobalt flax
#

heres the doc on .get()

#

"Return the value for key if key is in the dictionary, else default. If default is not given, it defaults to None, so that this method never raises a KeyError."

#

so like i gave a default

#

how else do i give a default

cerulean ravine
cobalt flax
exotic flax
#

typically you don't use dunder variables unless you're messing with things python level

cobalt flax
#

so i thought its valid if its given to me!!!

dull dune
#

in fact, in the docs if you hove ryour mouse over that trailing slash it tells you what it does

exotic flax
#

which IDE

cerulean ravine
cobalt flax
#

i'll just do off topic

exotic flax
#

I've only ever used dunder variables (double underscore) when I was messing around with repr so I can make a d20 function that gets a random number and load it into a python interactive terminal and then be lazy and type d20 instead of d20() or d(20)

certainly possible but no sane person would consider the effort spent to be worth it, especially when you can just make it a script that takes user input instead lol

#

iirc str and repr both had to be edited, and i used 3 layers of abstraction with decorators to get it working

dry pike
#

that's normal

exotic flax
#

do you mean common ones like init ? or in general?

cerulean ravine
#

dunder methods (with two underscores leading and trailing) are very different than __variables

exotic flax
#

fair, I've been smashing my head into js too much recently, yes there's a difference btw dunder variables and methods πŸ˜…

#

in js my brain just treats everything as a variable even methods

unreal terrace
#

Can I beginner ask questions here ??

spice hill
#

I wonder, would anyone be interested in a quiz about re similar to https://fstrings.wtf/? It seems like I'm learning new WTF moments every time I open the re docs.
I would make it python-independent but I don't know much about other languages' flavours

cerulean ravine
cerulean ravine
exotic flax
#

really? I do it all the time and I've worked with people who do

unreal terrace
# cerulean ravine yes!

Well I have just started learning Python and I know basic OOP but I want to practice it well like what's the best way to do that ??

exotic flax
cerulean ravine
harsh anchor
#

i think most people use "dunder" to mean __variable__

spice hill
unreal terrace
edgy krakenBOT
#
Kindling Projects

The Kindling projects page contains a list of projects and ideas programmers can tackle to build their skills and knowledge.

unreal terrace
cerulean ravine
shrewd pine
spice hill
#

so just re

shrewd pine
#

ah ok

spice hill
#

but the $ thing for example is inherited from PCRE

cerulean ravine
shrewd pine
#

end of string but not including a trailing \n

spice hill
#

apparently in PCRE there's a flag to disable this

shrewd pine
#

is it just a single \n?

spice hill
#

\r\n also doesn't work

shrewd pine
#

because python translates the ||icky|| CRLF to ||nice|| LF

#

(by default, at least)

spice hill
#

when reading a file

shrewd pine
#

yeah

dry pike
#

LF(G)

spice hill
#

liquefied factual gas

exotic flax
zealous edge
#

who thinks I should make a website a bit like bit.ly but for short links, image upload and pastebin

granite wyvern
# spice hill when reading a file

The end-of-line vs newline thing really only matters when searching multiline text, where there's a choice about whether you want $ to mean and end-of-line eg a newline or end-of-string. Personally I usually want end-of-string for $.

If you're not doing multiline stuff, just rstrip("\n") and not worry.

for line in file:
    line = line.rstrip("\n")
    regexp matching here, with no $ ambiguity
zealous edge
#

that would be cool 😎

cerulean ravine
spice hill
pine lake
#

Stupid question
New computer, what Python version should I install

gaunt badge
#

I think the reason for the existence of url shorteners mostly doesn't exist anymore. With the exception of QR codes maybe?

spice hill
#

Of course, once you know about this, you will rstrip or just use \A and \Z

#

Have long URLs stopped existing?

zealous edge
#

maybe I start slow and then pick up the pace

gaunt badge
granite wyvern
cerulean ravine
gaunt badge
cerulean ravine
spice hill
granite wyvern
gaunt badge
gaunt badge
spice hill
granite wyvern
spice hill
#

or I guess the py launcher works too

fathom pasture
#

does python have a wrapper for windows console api or a tui lib for it like it have curses, termios etc for unix
in stdlib

granite wyvern
#

Don't get me started on mailers with 100+ char URLs split over lines.

edgy krakenBOT
gaunt badge
fathom pasture
spice hill
#

no idea, sorry

soft turret
#

How do i make an input so that the user inputs as many tasks as they want until they want to stop? when they want to stop then enter a key

spice hill
#

but probably not

granite wyvern
zealous edge
#

I just HATE html and css

#

it's painful 😭

gaunt badge
cerulean ravine
fathom pasture
granite wyvern
zealous edge
spice hill
#

(or if you want e.g. 24-bit color)

granite wyvern
fathom pasture
#

yeah I would use textual but I am not leaving stdlib

#

and I am even fine with no color(just black and white)

granite wyvern
cerulean ravine
fathom pasture
#

that uses windows virtual term sequences api

#

requires enabling explictly though thats 2 lines if you are already using kernel32.dll from ctypes and msvcrt

fathom pasture
# fathom pasture windows doesn't support ansi nicely

and in fact it only started supporting some parts of posix api via a native translation since 2014 release of windows 10 and that behaviour is also inconsistent across versions, newer ones support more but older ones will still struggle

#

and its still incomplete

nimble cairn
#

Hello

fathom pasture
#

they have a milestone for having complete support somewhere in future enough that they will natively port and develop ncurses for windows

granite wyvern
fathom pasture
slate wren
#

πŸ‘‹

cerulean ravine
scenic finch
#

HTML is fine if you have copilot or something

cerulean ravine
fathom pasture
unborn lagoon
#

I'm pretty sure @apply is supposed to solve that last one.

fathom pasture
#

css works best when scoped

dry pike
#

vue SFCs

runic flower
fathom pasture
cerulean ravine
fathom pasture
river needle
#

πŸ‘‹

soft turret
#

Guys how do i acc make something runnable?

#

Like how can i make the python code work in an app that a person can download lets say

#

and how can i make it so i know what those people in my app are doing

runic flower
runic flower
soft turret
granite wyvern
steel whale
#

how do I build Kivy apps for android?

runic flower
#

yeah, if you want an html based todolist that certainly sounds like a web app.

soft turret
steel whale
granite wyvern
soft turret
runic flower
granite wyvern
#

Well a TODO list is just a list of things to do, maybe with frills like due dates or repeats etc.

A user might run your app locally, and store the list locally, in a file.

steel whale
runic flower
steel whale
runic flower
#

I had fun with kivy, really enjoyed it, but there were things I wanted that it could not do so I switched my interface to web based before I actually got to the "move it to my phone" stage. Yeah bulldozer sounds right.

cerulean ravine
simple willow
#

Would Windows Subsystem for Linux be useful to learn for python?

cerulean ravine
simple willow
#

ah ok

pastel sluice
#

@simple willow WSL is useful if you have things you want to run in Python that are Linux-only (certain modules only work on Linux), but for most "vanilla" applications Windows is fine

slow rivet
#

Because wsl let's you continue to use windows at the same time

granite wyvern
#

Switching back and forth is pretty tedious. With WSL you can use windows or use linux at the same time.

pastel sluice
#

dual booting is deeply inconvenient

slow rivet
#

Some people also just prefer a Linux environment for development, stuff like bash or nix or whatever while wanting their main window manager and os to be windows (for some reason)

simple willow
#

my parents don't really want me to dual boot or install linux on this laptop

granite wyvern
pastel sluice
#

nope, it's a real Linux

#

And you now have quite a breadth of choices for which Linux to use, too

granite wyvern
#

WSL runs a full Linux (usually an Ubuntu) in a VM.

slow rivet
#

(why are your parents opposed to Linux?)

granite wyvern
#

With dual booting you have to take care to partition to make space for the linux or windows, and not have one tromp on the other.

simple willow
granite wyvern
simple willow
#

They don't mind VMs, but installing other Operating Systems directly on the computer is a no go

granite wyvern
simple willow
granite wyvern
granite wyvern
charred tusk
#

what do patches know about security anyways

simple willow
slow rivet
charred tusk
#

N-1 stays decently supported for a while

granite wyvern
#

We're a mix.

charred tusk
#

Windows adamgross

granite wyvern
silver plover
#

Freedom isn't free.

slow rivet
#

If anything if they don't like forced changes to the os etc etc Linux is much much much better, windows loves forcing bs updates on people

dusk adder
#

leaving windows was a good decision

silver plover
pastel sluice
#

some people use Windows because they actually want to, or because they have no choice.

silver plover
#

Why would anyone care what you use?

granite wyvern
#

Ignore the haters. There's a big mix of desktops in use here.

slender urchin
#

I only have a windows install because of some windows only software

pastel sluice
#

most of the insults seem directed at Windows users, tbh

spice hill
#

i don't think it's worth spending time with people who insult you because you use the wrong operating system

pastel sluice
#

I use Windows on my own systems, and my remote hosts are all Linux; the difference has never been a problem

silver plover
#

People online with with strong absolutist statements are people to be ignored.

granite wyvern
# pastel sluice most of the insults seem directed at Windows users, tbh

Well people on UNIXlike systems tend to not like Windows. Certainly, on a personal basis, I want to throw a windows machine across the room in rage after I've been failing to use it for a few minutes. But for people comfortable there, there's no general reason to try to change their choice. Python certainly works on Windows.

pastel sluice
#

pretty much. I've been using Windows for a long time, I'm familiar and comfortable with it.

silver plover
#

My desktop is windows, laptop MacBook, and I use Linux (wsl or on aws) daily

granite wyvern
#

it's useful.

pastel sluice
#

it does help. my own familiarity with Linux is limited but I can get Python stuff done with it

slow rivet
#

Meanwhile one of my main reasons for switching to Linux were tilling window managers, and my reason for staying has been windows 11

granite wyvern
#

Yeah. I don't use tiling window managers (they tend to autoplace things) but I certainly tile my windows, just with key bindings for "full screen", "left half", "right half" and so on.

hearty bridge
#

I am making a WhatsApp AI chatbot via code, I am stuck

#

Can anyone please help? The message sent by user is not detected and showed in my backend via the web book.

slow rivet
subtle coyote
#

What's the most interesting thing y'all have ever worked on?

hearty bridge
#

I had added the Ngrok call back, URL. But it was still not working.

granite wyvern
#

I use many wokrplaces. ("spaces" in macOSX speak, desktops in the X11/Linux/UNIX world).

subtle coyote
scenic finch
#

I dual boot and it’s the opposite for me

#

Windows breaks half the time and Linux always works 😭

slender urchin
#

What are you doing to it lol

#

Generally when I see someone say there windows constantly breaks the have tried "debloating" it

granite wyvern
# slow rivet I usually have around 3-4

1: home/hosuehold/family, 2: work1, 3: persoanl code, 4: general web browsing, 7: reading, 8: work2, 9: work3
Or variations on that, if I'm using "numeric" desktops. Used to use named desktops when Linux was my desktop.

slow rivet
#

I generally have:

  1. Programming (terminals, editor, browsers)
  2. Discord
  3. Games

And then on a second monitor I often have YouTube open

granite wyvern
#

Discord/slack/teams/signal are all "all desktops" apps for me.

#

6 was games for me, but I don't really do that much.

slow rivet
#

I guess with niri it would make more sense to keep games and discord on the same workspace, but this layout is a bit of a muscle memory from using non-scrolling wms

granite wyvern
#

I'm a huge fan of MacOS' Cmd-H "hide" keystroke. Just withdraws all the windows for an app. Great for discord etc.

slow rivet
#

One thing I should get better at is using different browser windows for different groups of stuff

#

Having 50+ tabs in one window always hoping back and forth isn't exactly efficient

granite wyvern
#

And as of a year or so ago, firefox started remembering what desktop a window was on on restart. So useful.

subtle coyote
#

Guys I've come to a realization that I haven't made anything that I could actually show off 😞
Just some python scripts that do what I need + some 2d games back in day

#

I feel so bad

granite wyvern
#

A lot of what I do is scripts. Nothing wrong with that.

charred tusk
#

Scripts are great for consistency

slow rivet
#

It took years before I made something that got "popular" a like a year after that for me to start work on a project I actually fully felt proud off and felt is useful.

#

Being good at programming and being good at ideas is two very different things

ashen cipher
fervent matrix
subtle coyote
#

I've wasted so much time..

subtle coyote
slow rivet
slow aspen
#

I didn't start until the last 6 months of the university, it's not that difficult honestly to get to a decent understanding of things

ashen cipher
subtle coyote
subtle coyote
slender urchin
subtle coyote
#

Oh I see

ashen cipher
slow aspen
ashen cipher
slow aspen
soft turret
#

Why cant i write in my gui? i want to make it like a note if you get what i mean but it doesnt let me write in it

charred tusk
#

TL;DR: its me

ashen cipher
dry garden
runic flower
slow aspen
fervent matrix
subtle coyote
charred tusk
#

Getting all official

slow rivet
#

Yeah felt like it was org time

ashen cipher
slow rivet
#

Finally got two whole good ideas, got to keep it separate from my dumpster fire of normal repos

dry garden
ashen cipher
#

a lot

dry garden
ashen cipher
#

maybe not per day

#

between -1 and 25

slow aspen
#

The only reason I got into python and webdev was the requirement by the university to build a final year project, I come from an electronics background, so I had to learn this to stream record and showcase the data the electronics were collecting

dry garden