« first day (4079 days earlier)      last day (1094 days later) » 

01:53
what- i thought it was read only (the chats)
 
1 hour later…
03:00
@AnttiHaapala o/ Indeed! It's been a wild while...
Turns out that working on Open Source tech fulfills a lot of needs that I was coming to SO daily for XD
03:59
Can anyone please help me I can't figure this problem out?
import pandas as pd


df = pd.read_csv('chim_work.csv')

df_col = df[['ID #','Init Acct Type','Subs Acct Type','Max Days Diff']]

df_drop_null = df_col.dropna()

df_group = df_drop_null.groupby('ID #')


for i, d in df_group:
dfn = d.drop(columns=['ID #'])
print(i)
print(dfn)
I have an ID# for each 3 column Dataframe. I want to figure out which dataframes are duplicated (have the exact same data but a different ID#)?
 
2 hours later…
06:14
take a look at the df.duplicated method with the subset parameter
i suppose that might not be ideal though. you could simply make a version of the dataframes without the id column and then just use df.equals amongst themselves
 
2 hours later…
08:44
@NordineLotfi You might want to use an @decorator instead. A bit more typing, much less headache.
 
2 hours later…
11:05
Has anyone ever reset NVRAM or PRAM on a MacOS? I see a lot of guides suggesting it as a way to fix a blank app store screen but it comes with things like "Doing so will wipe out some of your settings such as Display, Sound, or time zone". This makes me think a programming laptop could go boom :/
It's not as scary as it sounds, but I admit to creating a backup before resetting either.
So far nothing went kaboom for me.
I just have images of it resetting PATH or something daft and all the disembodied servers and services I'd be left with :O
Nah, it should only wipe some settings of the system itself. So some of your system preferences like power settings, screen saver, and display settings may be gone.
I've occasionally needed it when docking station and external monitors screwed up the display settings.
Oh, well that makes it sound a lot more mundane than I feared. Thanks :)
11:49
I have lists that are populated with datetime.datetime objects and each list is assigned to one cell per row in a pandas dataframe. I'd then proceed to export the dataframe using dataframe.to_csv(file_path) then re-import the .csv files in the future using pd.read_csv(file_path, parse_dates=True). Is this fine and wouldn't incur any data loss? Not really used in dealing with dates
12:16
@Arne if you had to use an FST engine for NLP what would you choose? Something Python oriented and currently well supported with an active community. I started by looking at a Python wrapper for OpenNLP but I was hopping for something having Python under the hood not Java.
@bad_coder something like spacy.io ?
@JonClements that was my second guess thus far... I'm still looking into spacy atm.
@JonClements mmm, now that I'm looking at Spacy again it seems to fit my requirements nicely, thanks. Anyway, I know Arne looked at NLP so maybe he can add some more context to this. If anyone else has any ideas I'd love to hear them please ping me.
12:41
i dont know fst is. but in general, for python nlp tasks the big names are spacy or NLTK
12:55
Perhaps FST here means Finite State Transducer, a thing that I know nothing about
@bad_coder I'm not firm in NLP since a while, so I don't know what the ecosystem is like anymore. My guess would have also been spacy, and I usually warn people away from NLTK, unless they are students.
curious, what about being students makes NLTK okay?
usage in academia
er... i worded that weirdly.
it's a learning tool
13:01
Gotcha
13:19
@Arne that was my impression after an overview of the NLTK API, good if you want an exotic implementation ready to go but generally clogged and not intuitive. I am a bit surprised to see spaCy with only 3k Qs's though.
Question count is usually a good indication of user base and popularity.
The overall NLP Python universe is also surprisingly small.
Thanks @Arne I appreciate the help you gave me. o/
@bad_coder thats not the overall universe, that's the universe when you take away the two biggest players
@bad_coder you're welcome =)
granted, I'm not sure whether SO is a good indicator of the nlp space at all, since it's not well suited to the kind of issues we face in NLP
13:38
That reminds me, I've been meaning to see if there are any translation libraries that support English<->Japanese, and can work offline...
I suspect it will need a 100GB database, but that's not a deal breaker
@ParitoshSingh thing is most of the questions I see coming in on NLP related tags are from University students that are just starting out, so there's not much to build on. Those Q's would generally require writing an introduction and the user accounts themselves are in the 1rep range so even if you wrote a good answer it's unlikely you'll see the OP ever again.
@ParitoshSingh on the other end of the spectrum you'd have more or less experienced programmers with what are likely very localized Q's that require a ton of expertise to answer accurately. Just the thought of writing up a question has me prefer solving it by my own means.
13:54
Yep I've observed that as well
@bad_coder classic
@MisterMiyagi oh, you mean for generating argparse option for each function? I guess this would be better than my initial idea of using for loop + argparse yeah :) Thanks
right now I feel like I nearly managed to make it work like I want except for when I need to call a function calling another function with it's separate arguments on the commandline/through argparse, but otherwise this looks promising
14:39
@Kevin im a bit surprised how hard this seems to be to find. There's offline apps for translation, but specifically a library seems tough to find.
15:15
late morning cabbages, folks. Potato?
I just got a scammer text claiming that <phone company I have no relationship with> overcharged me and I have a refund in my name. Now I wonder if someone could use nerdsniping to successfully engage me in a scam before I knew what's happening. I can see myself responding to a "what's the best way to store/query this data" question
16:01
"Can you demonstrate how to use log4j? Here, use this one specific sample string..."
if the logging server crashed, you have passed the test. Also, depending on where this is happening, you may either become senior devops/security or be sent to jail
They can't jail me if I delete the law
ahh yes, the lawging server would have crashed :P
I find it interesting that this is valid Python syntax: () = () (but I don't know the chat-compatible markdown to write it as code here)
Yeah, it's an odd one
16:16
or with some actual function: () = g(), where g is a generator, to make sure it's empty.
Tuples can go on the left side of an assignment statement, e.g. (a,b) = (2,3), and I guess they decided that empty tuples may as well be allowed. Costs zero extra development effort.
there's nothing to assign. Nothing gets assigned to. The first part is easy. The second part... breaks my brain a little. I would have expected python to want to assign None to some variable. oh no wait! None is a thing. So the only way to assign nothing is to throw it away, which means the var would get immediately GC'd
Is it actually a tuple, though? On the left hand side?
I think they call it sequence unpacking in the Python tutorial.
16:17
In [135]: a = ()

In [136]: a
Out[136]: ()
It's syntactically a tuple. Whether it "is" a tuple in the truest sense of "is", is a difficult philosophical queestion
with a = () it,s a tuple, but the left hand side of (a, b) = [1, 2] looks like a tuple, but does any object of type tuple get created? I believe not.
```python
(a, b) = [1, 2]
```
Foirmally, the left side of an assignment statement is a target list
what is the correct markdown syntax to write code in chat? I forgot.
@gerrit no, neither () nor [] on the LHS denote a tuple/list type.
It's more akin to a pattern.
16:19
@gerrit Consult tinyurl.com/urnzp7k
@Kevin Ah yes, spaces. I forgot, thanks for the link.
@gerrit I agree. That's what I was vaguely gesturing at with my waffling about "is"
I forgot that
[a, b] = [1, 2]
is also allowed
dis.dis("[a,b] = x") shows that, by the time the bytecode is being composed, Python already knows the contents of the target list, and emits simple static STORE_NAME instructions for each variable. When the code actually runs, there's no need to keep those names in an actual tuple.
Oops, I used square brackets instead of parentheses there. Moot point, since the dissassembly is the same for both. And for a,b = x as well
16:43
If Lisp ever finds out that python has parentheses that do nothing, it's gonna die from a heart attack
(cond (know lisp (ignore python ('(,')))) (die) (carry_on))
@MisterMiyagi <screams into the void> isc.sans.edu/diary/…
@roganjosh the void mutters back in an incomprehensible language. Roll perception or arcana (whichever is higher) to understand what the void is saying back to you
I guess I can't roll perception because that article is a few days old and I hadn't seen it, so I'll have to go arcana
Well, on the bright side, responding to follow-up security advisories should be easier than responding to the first announcement of the exploit, since the hard work of "finding everywhere in your entire system where log4j is used" can be reused every time
16:58
It's not just finding, though, is it? It has to be fixed. So now I have to start the loop of fixes again
The other day I saw passing mentions of drop-in patches, which I assumed didn't require strenuous thought. But that was for an earlier advisory. All bets are off for this one.
Even if a very easy patch is possible, it might take a while for the security masters to write one up and publish it, and for the news to wind through social media channels onto your timeline
I assume all infosec communication happens on twitter because that's the only place I see it as an outsider
@roganjosh And here I was afraid the fun was already over!
Gotta love Christmas time! 🎄
<maniacal laughter> I think I've lost the plot at this point
Dumbedore apparates in front of you and says "use the force" and a keyboard appears in front of you. You see a git commit log on the screen in front of you
@roganjosh Plot twist: There is no log4j vulnerability. All warnings are posted by bots exploiting a Python logging vulnerability.
Also, The Doctor will arrive soon, wave his/her sonic screwdriver and make it all go away.
17:10
Don't. Even. Start.
Oh Doctor, where art thou?
Allons-y!
Doctor Where is an unaffiliated entity, and currently hiding from the BBC
I don't honestly know what I've even done this week. I'm trying to recoup annual leave that I couldn't take through the year but we get crap like this
"2.15.0 isn't enough" - yeah, I'm flipping desks at this point :P
You can always downgrade. Half our services aren't even theoretically vulnerable because they are too yaming old.
17:16
It's embedded in the libraries we're using. So unless you can monkey-patch Java or get a PR approved, I don't see what we can do
I think the exposure is super low, but we've just started getting emails from customers asking us what our procedure is for handling this. This is probably going to grow
May your suffering today earn you dividends tomorrow. Whether it be a fat bonus, or social clout, or experience points towards the infosec-adjacent class of your choice
In a parallel universe, they discovered a vulnerability in punch cards last week. Scientific computing is practically gone. Public services are safe due to Stone Tablet Techâ„¢.
Hello
I think this counts as a qualifying event for you to change to the renegade path and start writing exploits yourself
17:19
@roganjosh "We did all that we could." sounds like a pretty reasonable state.
Put a tickmark in the "tragic backstory" and/or "becomes the very thing he fought" boxes on your character sheet
@Kevin "Breaking news: The log4j LDAP exploit has been fixed by crashing every LDAP on the planet."
@MisterMiyagi Totally agree... it's just that that requires doing what I can do :P
Which, in theory (thanks, YouTube) is boundless
Actually, it's probably LinkedIn that tells me how special I am
@roganjosh Well, you're discussing the matter with international experts right now. Sounds good to me. :P
Begin rant. Statements of the form "I did my best" or "we did all that we could" are subjective to the point that I consider them meaningless. From a literal standpoint, "All you can do" includes selling your organs on the black market and donating the proceeds to Krebs on Security. If you still draw breath, you didn't do all you could. End rant.
17:27
I suggest not posting that on LinkedIn.
I think when people say "I did all I could do", they mean "I did an amount of thing that a reasonable person would consider reasonable, and if you tell me 'well I am a reasonable person and I dont think you did enough', then were gonna wrassle right here"
Unless you're a tortured cocoon that emerges as a butterfly at the end, you'll be getting no likes, I'm afraid
Or, substitute out wrasslin' for whatever your local custom is for resolving impugns of honor. Swordfight, passive aggressive poetry, whatever
I think I could get likes for my "no such thing as your best" philosophy if I couched it in terms of the Rise & Grind mindset. "Kings, even if you think you're giving 99%, you can still give an extra 10% on top of that, and that becomes your new 99%"
To explain more, I turn the mic over to my guest speaker, Xeno of Elea...
I mean; we can test this. Try "Did you donate your kidneys and draw your last breath?" under one of the "inspirational" garbage posts. We'll get a quick answer, I think
I try to imagine I'm giving my long-term-all-I-could. Selling my organs to some sleazy US code shop might get this issue fixed, but how about the next?
17:36
I think it's reasonable to say "donating my organs and dying today does not maximize my total lifetime contribution to society". I would like proponents of this line of thought to say "I am doing all I can" rather than "I did all I could", in order to make clear that they are still in the process of doing, and will continue to do until they pass away of old age.
What if your liver went on to save a genius, but chronic alcoholic, to give them a few more years, MM?
I don't know whether this debate is gonna go anywhere fun :P Maybe we should change topic
For the record, I do miss the opportunity to get drunk on the company Christmas party.
Hi, guys, Can I ask simple dummy question ?
Simple questions are allowed, if you ask it beautifully
data = [calc(x) for x in data if calc(x) > 10]
17:40
I'm trying to remember a term here. Over optimization? early optimization? It's when I write very optimized code right off the bat, and paint myself into a corner with diminished flexibility of my code. Can someone tell me the term I'm trying to (but am unable to) name?
in this case, calc function will be executed twice for each x
Uh-oh... let me grab my club real quick... might need to play whack-a-walrus
Am I right ?
@LeadDeveloper For future ref: we have a formatting guide
@LeadDeveloper Yeah.
17:40
@LeadDeveloper yes
@roganjosh Thanks.
How to avoid it ?
how to avoid... what?
Why is it an issue?
Don't put it into a list comprehension
@inspectorG4dget "premature optimization"?
17:41
@Aran-Fey yes! that's it! thank you
@CoolCloud Perhaps the call has some undesirable side effect, like it has to send a message over a very slow network
If you want to evaluate the function once per cycle then there is no need to put it in a list comp
@Kevin yea thought so or even print() that gets executed
@LeadDeveloper Use an assignment expression, a map or an inner generator expression.
data = [x for x in map(calc, data) if x > 10]
Of course I can do something like this.
result = []
for x in data:
r = calc(x)
if r > 100:
result.append(r)

but I want to do it with one line like below.
but in this case calc function is executed twice for each item x.
result = [calc(x) for x in data if calc(x) > 10]
Of course I can use filter after this. but asking to know whether there's any other way for this.
17:44
@MisterMiyagi Ooh, a legitimate use for map. That's rare
#approach 1: two passes through the data
kevin_was_here =  [calc(x) for x in data]
data = [x for x in kevin_was_here if x > 10]

#approach 2: assignment expression
data = [kevin for x in data if (kevin := calc(x)) > 10]
@MisterMiyagi Got it. Thanks a lot.
haha.. I'm so dummy.
if there's a bottlenecking side-effect in calc(...), a valid approach might be to use mp.Pool. But fools rush in where angels fear to tread
@MisterMiyagi Thats some nice thinking
I know that assignment expressions have a bit of a mixed reputation among us, but this feels like an intended use case to me
So at the very least you're not creating an affront to nature, you're just using a silly feature for its silly purpose
17:49
I disagree. It's unnatural for a walrus to be in a python
I am still confused with walrus operator, its prolly because I never got the time to use it since I practiced mainly in python 3.7 and did not update till I stopped practicing
I don't think the operator itself is difficult, but it does require a relatively thorough understanding of Python's execution model.
Wait, where's your mouth? And who did you steal that 2nd nose from?
18:09
Topologically, a mouth and a nose are pretty similar
Tempted to say "equal" but there might be a column or a vent or something that I don't know about
18:46
Can anyone please help me understand how I am supposed to find duplicate dataframes in a groupby python object where the key is an ID# and the value is a 3 column dataframe?
for key, value in grouped_object:
if value == (any other value in groupe_object) print the list of keys
If you want to find duplicate items in a list of hashable objects, then one straightforward way is to use a collections.Counter. But I don't know whether dataframes are hashable or not.
pandas devs, please implement a hashable FrozenDataFrame class, thanks in advance
Can we have a Minimal, Reproducible Example? Because I don't understand the question
I understand about 65% of the question, and I too request a minimal reproducible example
I see that stackoverflow.com/questions/70371461/… has a little more information, but without the contents of chim_work.csv, it's still not reproducible
And here I thought "groupby python object" was referring to itertools.groupby...
I've now come up with an additional plausible interpretation of the question, so I'll have to divide my understanding between the two of them, putting me at 32.5%
18:58
Thanks for responding.
I hope you're not too frustrated that I don't have any concrete advice to lend at the moment. When there's wiggle room in a problem description, then I am awash in a sea of overthinking
If you have 4 columns of data in a CSV file. You group by ID# which is a column. You return a python object whereby the key is ID# and the value is the other 3 columns (a 3 column dataframe).
How do you find which keys (id#s) have the same value(3 column DF).
Which df ( the value in the python object) is a duplicate of another?
Ok, I'm back up to 65%
Are the values in the dataframes hashable?
19:04
OUTPATIENT INPATIENT 3
EMERGENCY INPATIENT 3
OUTPATIENT OUTPATIENT 0
EMERGENCY OUTPATIENT 0
OUTPATIENT EMERGENCY 0
EMERGENCY EMERGENCY 0
INPATIENT OUTPATIENT 0
INPATIENT EMERGENCY 0
INPATIENT INPATIENT 3
2 of the columns are text 1 is a number.
Ok. Is the number the "id#" you mentioned before?
df.equals(df) could compare for equality between dataframes but I don't know how to compare the first dataframe to all of the datafframes in the object?
No.
I thought I covered that.
I already grouped the data by the ID# which is the key, the value is this resulting 3 column dataframe.
Ah yes, I see where you said that earlier.
I have to figure out how to loop through the object and check if each value (the df) has a duplicate
but don't know how
19:09
I have some ideas, but I would need to see the id# of each of those rows so I can test my prototype
what do you mean?
aran-fey so that converts the dataframe into what exactly? and why do we need to convert the dataframe to compare eqaulity?
Perhaps I've misunderstood the question. Does chim_work.csv have four values per row? Each one representing one of 'ID #','Init Acct Type','Subs Acct Type','Max Days Diff'? If the data you start with has four columns, then the data you show me should also have four columns. The data you have showed me has three columns.
@CarsonForeman Into a value that you can compare more quickly than a dataframe. And you don't have to, it's just more efficient
Yes. But I grouped the data by the first column ID#. I don't need that column anymore since the data is already grouped. So I dropped that column.
for i, d in df_group:
dd = d.drop(columns=['ID #'])
so now each ID# is attached to a 3 column dataframe'
Thanks aran-fey
Ok, so the data you've shared is what it looks like after you've run the first half of your program, but before you've run the ... in df_group loop? I would like to see the data before you run any code at all.
19:15
thats simply a 4 column dataframe
Great, if it's simple then you should have no problem showing me the entire thing.
100 OUTPATIENT INPATIENT 3
100 EMERGENCY INPATIENT 3
100 OUTPATIENT OUTPATIENT 0
100 EMERGENCY OUTPATIENT 0
101 OUTPATIENT EMERGENCY 0
101 EMERGENCY EMERGENCY 0
101 INPATIENT OUTPATIENT 0
101 INPATIENT EMERGENCY 0
101 INPATIENT INPATIENT 3
4 columns. I grouped by ID# to give me the 3 column DF for each id number.
Ok, progress is being made :-)
then dropped ID number after the data is grouped by id
thanks so much!
Now I want to check for duplicate 3 column dataframes
So what's the expected output for this input? I'm guessing it's "no duplicates found", correct? Because looking at the rows with the id 100, they all seem to have distinct combinations of values. And likewise for id 101.
19:19
Thats dummy data.
Once the data is grouped by ID I am trying to find the duplicates.
Well, there's certainly nothing wrong with creating a test case that returns an "I didn't find anything" result. Good code coverage in fact.
100 OUTPATIENT INPATIENT 3
100 EMERGENCY INPATIENT 3
100 OUTPATIENT OUTPATIENT 0
100 EMERGENCY OUTPATIENT 0
100 OUTPATIENT EMERGENCY 0
101 OUTPATIENT INPATIENT 3
101 EMERGENCY INPATIENT 3
101 OUTPATIENT OUTPATIENT 0
101 EMERGENCY OUTPATIENT 0
101 OUTPATIENT EMERGENCY 0
here
i fixed it
so with this data once you grouped by ID
you would see that ID 100 has an identical DF to ID 101
Hmm I see
This is slightly different from my original guess of what the goal was... I'm glad I got some clarification
I have an idea for an approach, which goes something like:
(might need a minute for this one, please hold)
from collections import defaultdict

#most of your original code goes here

ids_by_df = defaultdict(list)

for i, d in df_group:
    dd = d.drop(columns=['ID #'])
    ids_by_df[dd.to_json()].append(i)

for k, ids in ids_by_df.items():
    if len(ids) > 1:
        print("These ids are duplicates of each other:", ids)
I'm a little concerned about the to_json() call there, in the first loop. I'm pretty sure it works the way I want it to, but for large dataframes it may be quite slow.
19:32
Wow so this far more complex than I can understand.
Possibly there are alternatives to to_json that would work better... It just has to be a function that converts* dd into an immutable type, such as a string or a bytes or a tuple of immutable types. Ideally using as little memory as possible.
import pandas as pd
from collections import defaultdict

df = pd.read_csv('chim_work.csv')

df_col = df[['ID #','Init Acct Type','Subs Acct Type','Max Days Diff']]
df_drop_null = df_col.dropna()
df_group = df_drop_null.groupby(['ID #'])



ids_by_df = defaultdict(list)

for i, d in df_group:
dd = d.drop(columns=['ID #'])
ids_by_df[dd.to_json()].append(i)

for k, ids in ids_by_df.items():
if len(ids) > 1:
print("These ids are duplicates of each other:", ids)
this runs with no error but prints nothing
(*"converts" is not a formal term in Python, but maybe you get what I mean)
@CarsonForeman Hmm. Maybe I was incorrect to assume that a.equals(b) is logically equivalent to a.to_json() == b.to_json(). There may be a mismatch in what kinds of data (and metadata?) they're comparing.
I give up.
It doesn't seem like this should be this hard.
Just finding duplicate dataframes.
df.equals() i thought would be usefl
useful*
idk this is too hard for me.
thanks for helping Kevin
I have a second idea, that might be easier to understand
It might be slower though. Well, I'll explain it anyway.
19:36
I also tried converting the object to a dictionary
then creating a new blank dictionary and appending values that werent found in the other.
ohh somenoe just commented on reddit
df.groupby('ID').agg(tuple)
df.groupby('ID').agg(tuple).duplicated(keep=False)
for i, a in df_group:
    a = a.drop(columns=['ID #'])
    for j, b in df_group:
        b = b.drop(columns=['ID #'])
        if a.equals(b) and i != j: #possibly consider `i < j` instead
            print("These ids are duplicates of each other:", i, j)
This runs in O(N^2) time, which essentially means that a df_group with 12 elements will take 12*12 == 144 iterations to complete. Not a problem for your sample data, which has only two groups. Might be a problem for your real data.
19:57
THat looks more like something i can understand
it runs with no errors but returns nothing
import pandas as pd
from collections import defaultdict

df = pd.read_csv('chim_work.csv')

df_col = df[['ID #','Init Acct Type','Subs Acct Type','Max Days Diff']]
df_drop_null = df_col.dropna()
df_group = df_drop_null.groupby(['ID #'])

for i, a in df_group:
a = a.drop(columns=['ID #'])
for j, b in df_group:
b = b.drop(columns=['ID #'])
if a.equals(b) and i != j:
print("These ids are duplicates of each other:", i, j)
My take:
dfs_by_hash = collections.defaultdict(list)

for i, d in grouped_df:
    dfn = d.drop(columns=['ID #']).reset_index(drop=True)
    hash_ = hash(tuple(pd.util.hash_pandas_object(dfn)))
    dfs_by_hash[hash_].append(dfn)

for df_group in dfs_by_hash.values():
    while df_group:
        df = df_group.pop()

        for other_df in df_group:
            if df.equals(other_df):
                print(f"df {id(df)} is equal to df {id(other_df)}")
aran-fey
it ran
that was result lol
Works on my machine.
it ran with no error
just don't know what to make of the result
Sure would be nice if we had an MRE to test our code against, wouldn't it
I could post my code complete with output to show that it works as (I) expected, but I don't want to be the first one to post an MRE
20:11
whats an mre
Should look kind of like this, except you would show the output you want, and explain why that's the output you want
20:30
cbg all.
Catching up on this; why has nobody linked the formatting guide too?
I should put a shorter timer on these pastes... 1 week is too generous
Timeout immediately. If they can't be bothered to develop a time machine it's clearly not worth their time (;
20:50
I've actually been doing that all this time. The pastes are immediately deleted, then the paste id is re-used for the next upload, and it just happens to be code that looks like it might have been posted by me
The truth is I can't write python at all, it's all been luck so far
21:03
naturally :)
 
2 hours later…
22:42
Well, that's a surprising bop
https://www.youtube.com/watch?v=L1dU1HZ_73M
Hey cool I (srilyk) am 42 on the AOC leaderboard (:
@Aran-Fey I have mixed feelings about temporary file links. We want stuff in the transcripts to remain useful. OTOH, I guess a temporary file is ok if its contents aren't essential to the conversation.
@WayneWerner Pineapple! (I haven't actually bothered to look at AoC for the last few years).
Same. This is the first time I've bothered since... checks repo 2018
I'm taking it nice and slow this time - in part driven by getting my own laptop, and trying to keep work/play separate
Also I'm trying to stream solving them - twitch.tv/srilyk has my day 2... I failed to turn recording on for day 1 (:
23:33
cabbage world class pythonistas
cbg @ReblochonMasque
how to parametrize the format specifier for string formatting?
a, b, c = 1, 2, 3
print("a = {:.3f}, b = {:.3f}, c = {:.3f} ".format(a, b, c))
print(f"{a = :.3f}, {b = :.3f}, { c= :.3f}")
fmt = .3f   # <<== invalid syntax
print(f"{a = fmt}, {b = fmt}, { c= fmt}")
just give it a {}
>>> x = 3
>>> y = 2.3932343
>>> f"{y:.{x}}"
'2.39'
:facepalm: ok, million melons, i was confused. :)
>>> pts = 3
>>> print(f"{a = :.{pts}f}, {b = :.{pts}f}, { c= :.{pts}f}")
a = 1.000, b = 2.000, c= 3.000
When I first tried it, I thought, "There's no way this can work!"
And... I was 100% wrong, lol
f-strings are all kinds of cool and abuse-worthy
23:38
Yes, it is not readily obvious... i/e this obviousness level takes time!
>>> print(f"{'\n'.join(('a', 'b', 'c'))}")
  File "<stdin>", line 1
SyntaxError: f-string expression part cannot include a backslash
>>> print(f"{chr(10).join(('a', 'b', 'c'))}")
a
b
c
there are many shenanigans possible with f-strings, if only you care to ~fu...~ play around and find out
well heck

« first day (4079 days earlier)      last day (1094 days later) »