« first day (2854 days earlier)      last day (2108 days later) » 
00:00 - 19:0019:00 - 23:00

@user3483203 done
 
Always coming through :D
 
such conspiracy
 
 
4 hours later…
4:31 AM
@FélixGagnon-Grenier You noticed that all icons have changed, right? I like the new look, personally. I've been using the EAP/Beta/RC for several months already.
 
4:42 AM
cbg dear peaches and pears
 
5:35 AM
I have a list, populated with sublists. If...
for i in range(len(myList)):
        print(myList[i][0])
... produces the output consisting of all values indexed as zero in sublist equal to [i], it means it [i] is iterated on, right? But, how to iterate on the second parameter too - the [0] in this example?
 
6:33 AM
@IgorV. By writing a second loop within your first loop
for i in range(len(myList)):
  for j in range(len(myList[i])):
    print(myList[i][j])
that being said, in python you'd probably just iterate over the items directly instead of the indices:
for sublist in myList:
  for item in sublist:
    print(item)
 
cbg
 
cbg all!
 
Hi guys, new to python. Could someone tell me what's wrong with the following:
bool = true if (num % 2) == 0 else false
It says "NameError: global name 'false' is not defined"
 
6:45 AM
Typo false is False in pyhton
 
so true will be True?
 
Also just set the variable directly ` var = (num % 2 == 0)`
 
huh
thanks
 
pylint will give you automated feedback on many of these things
 
@Rishab Also bool is the name of a builtin, so avoid shadowing it.
 
6:51 AM
@IljaEverilä cool, thanks.
@shuttle87 I just dived into hackerrank and started.
 
@Arne I figured that that would be a solution, a second loop, but didn't know how to make it. Thanks a lot!
 
7:14 AM
cabbage gentle and nice people of the new COC
 
cbg-ning
 
7:44 AM
hello
 
8:05 AM
Cabbage
 
cbg @PM2Ring
 
8:21 AM
@Rishab you should probably give a tutorial a look for the basics :) The official one isn't that bad
 
@AndrasDeak
Thanks
 
You can also edit/delete messages for 2 minutes in chat
 
ok
 
I'm asking for specifically a link where it shows that this code is vulnerable, of course I know SQL injection exists, but to know mysql + python + improperly used variables or SQL query strings is vulnerable is far from common knowledge my friend. Especially for younger programmers, wouldn't you want the best for budding programmers? — Swift 15 hours ago
wow... 4 answers, 4 SQL injections.
 
And the comments there.. WTF
 
8:39 AM
@AnttiHaapala "I want the best for new programmers so please rigorously prove that my answer is harmful because I don't know better"
Also the newest xkcd is relevant
6
 
LMAO, that burn from the hover text...
 
9:02 AM
what's wrong with paper ballots :f
 
9:26 AM
of course that comic will always be relevant on SO
@shad0w_wa1k3r I'm not sure it's a burn. It's may be more about waiting for that brand-new branch of mathematics to distill down to actual applicable and secure applications
bah, these minor grammar typos annoy me to no end
 
@AndrasDeak ofc it completely misses the point.
 
9:55 AM
@AndrasDeak at current situation (market, developments, etc.) I'd consider that as a burn :)
 
Here is an interesting link from the thread for that comic.
Is it just me, or do others find this Java-esque code format really annoying? I think it's from hackerrank, or one of those competition sites. stackoverflow.com/questions/51763254/sum-path-coding-in-python
 
@PM2Ring thanks for the link, that is indeed scary (& very interesting) stuff
 
We occasionally get some pretty amateurish questions on SO from people who are writing code for medical monitoring. Of course, it could just be a class exercise, but you never know... I guess it's unrealistic to expect everyone working on such applications to be security experts, but you'd hope that someone on the team knows about security, and they get an expert security evaluation before rolling out software that could put people in danger if it were compromised.
 
I suppose people in important positions, who (can afford to / get) have dedicated security, would be considering all these scenarios as well.
 
@NChauhan You are not mistaken. list.append returns None, like all built-in methods that mutate a mutable collection. — PM 2Ring 27 mins ago
dict.setdefault :P
 
10:11 AM
It was only a few years ago, relatively speaking, that it was common for hospitals to ban the use of mobile phones, in case it interfered with any of their systems. So I guess those systems weren't very secure. I assume the situation has improved somewhat, but I have no idea by how much.
 
@AndrasDeak dict.pop()
 
meh, pop is always designed to give you an item
 
well, it was a mistake i personally dislike it, and try to claim it being objectively bad every now and then
 
@AndrasDeak Yeah, ok. :) I'll fix that comment.
 
@Arne how so?
 
10:13 AM
Since it was included, it should behave the way people expect it to, even if it is different from all the other mutating functions (checking out setdefault atm)
 
@Arne Dislike what? The rule that mutation methods should return None?
 
@PM2Ring I wouldn't call .setdefault an obvious exception, but this is just taste ;)
 
@PM2Ring No, the other way round. I like the rule, I don't like pop breaking it.
 
@Arne I'd think people would expect .pop to give you an item.
my notion is that it comes from stacks and you usually don't just discard the top of the stack
 
Yes, that's actually what I was trying to say. if pop is implemented, it should mutate+return
 
10:15 AM
@AndrasDeak Ok, it's semi-obvious. :) But a .setdefault that didn't return something would be pretty useless. :)
 
@PM2Ring it shouldn't be called "set default" :(
@Arne it mutates and returns :PP
 
I am having a hard time putting thoughts into words today..
 
How else would you get hold of the popped item?
 
@AndrasDeak what I should have said: "since a correctly implemented pop should mutate and return, it should not be included in the stdlib"
@AndrasDeak make do without pop
 
ah
as you know python has some features that sound really icky but are useful in a very small handful of use cases *cough* 572 *cough*
 
10:19 AM
ah, it's been a couple of days since I last discussed that one
I'd say 572 is more pythonic than pop by a long shot
 
@Arne But that's just silly. We need to be able to do stack-oriented stuff. So we need to have objects that behave like stacks and that have methods that can be used for pushing & popping.
 
for one, it doesn't mutate
 
meh
 
OTOH, I wouldn't be upset if list didn't implement .pop. Then people wouldn't be tempted to use it for stacks, they'd use deque instead.
 
@PM2Ring My opinion on pop was formed by 1) me never needing it, ever, and 2) seeing people use it instead of del
 
10:22 AM
those are two wrong motivations for forming opinion about a feature
 
trying to be objective is A LOT of work though
 
yes :P
still, "people abuse it in ways it was not meant to be used" is never a reason to hate a feature
 
hmmm
 
(I guess if it happens often enough one might argue that it's partly the designer's fault)
 
I gave him plenty of time, but I guess the FindPath guy's not going to make his question a MCVE, so I closed it.
 
10:25 AM
@AndrasDeak Isn't that the main point against 572?
 
@AndrasDeak That'd be like hating str because people do stuff like str("hello") :)
 
@Arne no. The way people will abuse 572 (as I fear at least) is by design
Remember the "leaking listcomp with side-effect" example
 
Then we can refine the feature hate condition list:
- people abuse it in ways it was not meant to be used AND
- that abuse has side effects (or something similar) than leads to ---bugs--- annoying SO questions
- it offends me esthetically AND
- I have too much free time
damn, multiline formatting got me again
 
I think you have the first one the wrong way
Or we merely disagree ;)
 
that's how I understood you. misuse is not reason enough to hate, but misuse that leads to bugs is
@AndrasDeak I guess I disagree with this one being an intended use
I might be plain wrong there, since the author of the feature might have auhtority in deciding his own intentions.. but hey, can't be right all the time
 
10:35 AM
I use .pop a bit, mostly in code that does Knuth's Algorithm X, like this. And here's a pretty interesting prime number generator that uses it.
But I will agree that list.pop does get used in a lot of code that could avoid it. One could say the same about .remove and .insert.
 
@Arne it's in the PEP :/
 
I am aware =(
 
That's as intended as it gets
@Arne my stance is that misuse from stupid users doesn't count. It's like hating sqlalchemy for all the injection vulnerabilities
 
@PM2Ring my_list.pop() vs del my_list[-1]
what do you prefer?
 
my_list[-1:] = [] ;)
 
10:40 AM
@AndrasDeak so if the PEP didn't showcase weird uses, you'd be fine with 572?
 
Less not-fine at least. I'd still worry for abuse, but as it stands it's advertised to abuse
 
I see. I guess I never gave the examples I didn't like much weight.
 
I'll see someone doing that on SO, tell them that this is confusing and hard to read, get pointed to PEP...
 
@AndrasDeak that's a new one..
 
"Yeah but I still think it's stupid" carries much less weight I'm afraid :P
I'm not optimistic about a healthy set of best practices (think convoluted listcomps) with that official attitude
 
10:44 AM
maybe we should write a wiki here, "how not to use assignment expressions"
and just link that
 
We'll first have to see how people start abusing it
 
Looking forward to it =D
 
@Arne In my own code, I'd only use my_list.pop() if I actually need the popped item. But if I'm using code written by someone else that does .pop and throws away the result, I won't necessarily change it. Eg, in that Algorithm-X code, there's one .pop call that does that, but I think it's ok because it's kind of consistent with the other .pop calls, so changing it to a del would spoil the pattern.
 
@PM2Ring Fair enough, I guess I'd decide the same way
 
10:53 AM
Hello everyone... Is there anyone who can hep me with tensorflow and tensorboard visualization? I want to see my training getting lively observed on the tensorboard.
 
@AndrasDeak Yeah, I just left him a comment, but I'm not hopeful of seeing any improvement.
 
@AndrasDeak I am still considering this code.. I always thought slicing creates a copy, how come it changes the original?
 
@Arne It's slicing on the left side, so it's saying where to mutate the data of the original list.
Pardon my dyslexia. :)
 
Hello!
Have troubles with flask :
I have view
@app.route('/get/<Symbol>/<Date>', methods=['GET'])
def get_data(Symbol, Date):

    print(request.args)

    return jsonify({"response": dumps(res)}), 200
But when I sent a request :
params={'Symbol':'AMD',
       'Date':'2018-4-10'}

r=requests.get('http://127.0.0.1:5000/get/', params=params)
print(r.text)
I get The requested URL was not found on the server. error
Any ideas on fix?
 
please stop posting unformatted code; use the "fixed font" button in chat.
you need /get/x/y to match your route...
if you want querystring args, don't put them in the route() call or the function arguments.
 
11:00 AM
@БеляковаАнастасия Is your flask running?
 
@БеляковаАнастасия Because params would get passed as "/get/?Symbol=AMD&Date=2018-4-10"
and whatever ThiefMaster said.
 
Ah, that did the trick. Thank you!
 
Is it possible that we can find the relationship what the tensorflow model is understanding from the csv that we have given for input?
For example if I am using RNN and giving the input csv as: gist.github.com/JafferWilson/d7010f299953acdf0fe5d7da94e58b6b then what the tensorflow will understand the relation between then. I am trying to run the program from Kaggle: kaggle.com/raoulma/ny-stock-price-prediction-rnn-lstm-gru/…
 
11:07 AM
Sliced assignment can be fun
 
@AndrasDeak it feels strange to use it..
 
this is the weirdest bit for me:
 
brb, gonna run it by colleagues to see if I am the only one who didn't know about it
 
>>> x = list(range(10))
>>> x
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> x[1:-1] = range(3)
>>> x
[0, 0, 1, 2, 9]
it took me a while to get used to it not doing elementwise assignment, but rather arbitrary replacements (i.e. the length can easily change, see also the del example)
 
Check out this awesome prime number sieve using extended slice assignment. Some ideas came from a SO answer, but I already had a slice based sieve of my own, and I've made a few improvements to Robert William Hanks' version. I don't think you'll find a faster prime number sieve in plain Python.
from itertools import count, chain, compress
def prime_sieve(n):
    """ Returns a list of primes < n """
    # Originally from stackoverflow.com/a/3035188
    size = n >> 1
    sieve = bytearray([1]) * size
    for i in range(3, 1 + int(n ** 0.5), 2):
        if sieve[i >> 1]:
            ii = (i * i) >> 1
            sieve[ii::i] = bytearray(-((ii - size) // i))
    return [*compress(chain([2], count(3, 2)), sieve)]
 
11:23 AM
only one knew and used slice assignment, and 4 our of 4 people agreed it's tricky
@PM2Ring understanding that one will be my exercise for today =)
 
:) One little trick it uses on the 2nd last line is that -(-a // b) gives the ceiling division of a / b.
 
11:46 AM
Is there no one in the chat room who can help me with the Tensorflow and tensorboard visualization?
 
apparently not
someone started a tensorflow room a few weeks ago, is that not active anymore?
 
I didn't see anyone there. Thats why I thought someone would help me as I am using it in python.
 
Yeah, I know. Your question is on topic here, it's just there seem to be only a few users around and none of them seem tensorflow-savvy
 
@AndrasDeak Yeah I guess the same ..
 
12:29 PM
Hmm, this is a stretch but since it's the Python room - anyone here decent with statistics?
 
How can someone (Skeet) who gets 80 upvotes in a single day, possibly end up with only +180 rep on that day? There was a “-20 user removed” but shouldn’t that be included in the rep cap calculation? Because at some point that +20 (likely) also counted towards the rep cap..?
@Benjamin Theoretically, or practically? :P
 
@poke :P
Well, I want to run an A/B test - the problem is there is no clear measure of "conversion" for a single user but rather for all users
Since the users are cooperating - I don't want to measure if N out of K users succeeded - I'm measuring a score of all users combined. For example I test 10000 users and split them into A and B, the score of A is 1.5% and the score of B is 1.0% - I want to know if that's significant basically
 
Uhhhm, maybe I don’t know statistics after all… xD
 
lol :D It's supposed to be easy - but all the material I find assumes users are independent
I'm building a distributed platform and the users are not independent experiments - I want to know what's the correct way to measure it. I can "bucket" users based on some random factor (like "all the users that started in a certain hour") and make the experiment repeated
 
Can’t you put all the cooperating users into a single “virtual user” which you then assign a score to?
Or is everyone working with everyone?
 
12:37 PM
Everyone inside A or B with everyone (in the same slot)
 
:/
 
Even if I split it per hour (for example, all sessions in a given minute/hour) I still don't know how to define conversion
Wasn't there an R room at some point :D ?
 
:D
 
hello all, what is the differences between

`*random_training_set()`
and
`random_training_set()`

def random_training_set():
chunk = random_chunk()
inp = char_tensor(chunk[:-1])
target = char_tensor(chunk[1:])
return inp, target
 
Isn’t there some statistics SE?
You might have some luck there!
 
12:45 PM
Looked at the latest question, will probably just email a friend who is a statistician
 
xD
Good luck!
 
Thanks for attempting to help :)
 
thanks @poke
 
My computer has adopted a habit of informing me "your wifi is disabled. Enable now? Y/N" every time I wake it up. This is a lie. My wifi is not disabled, and clicking either "yes" or "no" has zero effect on it, as does simply ignoring the box and leaving it open forever.
If this box is caused by malware, it's the un-stealthiest malware I've ever seen. I thought viruses liked to keep a low profile.
 
1:03 PM
It is a counter propaganda hack to make it seem like a harmful hack. The writers of the "malware" wanted you to complain so that it seems like malware is everywhere. Tell me, can you see if it is trying to count votes in the background?
 
There's a little gremlin behind the clock portion of the task bar. He's holding a note pad and doing a poor job of concealing himself
 
DSM
Morning cabbage for all.
 
cbgs
 
@piRSquared hey o\
 
o/ @AndyK
 
1:15 PM
brief cbg
 
DSM
Lot of Jon around lately! Even seen you on questions.
 
heh :)
 
^^ seconded
 
so - what scooby snacks have I missed out on recently? :p
 
Can I get a quick sanity check? Please run gist.github.com/pirsquared/11c3e6947f2cf4ae8adf08e00ecc17e3 and tell me what the first row for column 'A' says.
All good, False alarm
 
1:29 PM
\o cbg
 
DSM
@MooingRawr: rough little-round-ball lately.
 
yup. I do hope we decide to rebuild properly.
 
How to link class function to the tkinter button for reuse after pressing the button starts with the lines from tkinter import * followed by from PyQt5 import QtWidgets, QtCore, QtGui. Is this a thing? Is Qt interoperable with Tkinter?
 
DSM
I know less about Python GUIs than almost any other common application domain.
 
1:42 PM
2
Q: Converting Pandas DataFrame to sparse matrix

Akhil AlexanderHere is my code: data=pd.get_dummies(data['movie_id']).groupby(data['user_id']).apply(max) df=pd.DataFrame(data) replace=df.replace(0,np.NaN) t=replace.fillna(-1) sparse=sp.csr_matrix(t.values) My data consist of two columns which are movie_id and user_id. user_id movie_id 5 ...

 
I'm leaning 75% of the way towards "they're not at all interoperable, and OP is just trying anything and seeing what sticks"
 
@Code-Apprentice Oh, so it's not my legendary bad memory striking again? Yeah, I thought I'd noticed the step over and step in icons had changed too. I agree, overall it's a small but nice change
 
2:09 PM
@AkhilAlexander have you read any of the posts on how to write a question? You can start by writing a mcve Then go on to read stackoverflow.com/q/20109391/2336654. The point is, I'm not incentivized to answer the question because you don't provide enough information that makes it easy for me. If I feel that way, I'm sure others do as well.
However, I'm not even sure if I'm even on point because you just posted a link and didn't say anything.
 
DSM
I'm resisting the temptation to build a custom sleep class which supports this.
 
new sleep strings s"I love my dog {sleep(0.5)} I also love my cat". Was denied today due to the unnecessary anxiety it caused cats with regard to the perceived favoritism of pet owners towards their dogs. #CatsCare
Hah! I did it. Behold lameduh
def λ(sig, expr):
    kw = {}
    exec(f"f = lambda {sig}: {expr}", kw)
    return kw['f']

[*map(λ('x', 'x**2'), range(5))]

# [0, 1, 4, 9, 16]
4
 
2:37 PM
my god, what have you done?!?!
 
pep-031415 of course
 
Thanks, I hate it
 
now I know how gvr feels
 
2:52 PM
cbg
So there is no easy way to write a fixed width files from pandas df?
 
sure there is. "Easy" is relative. What are you trying to do?
 
cabbage
 
cbg
 
I know... lol...easy for you, hard for me, I'm resurrecting and old crop model that needs space delimited inputs where the format is as follows:
2007 27 3.9 5.0 -3.0 0.1
2007 28 9.0 7.3 -3.2 0.0
2007 29 10.7 9.9 -1.2 0.0
well with consistent spacing
 
DSM
3:06 PM
I'm actually not sure of the best way to write fixed width files from pandas.
 
@DSM I remember having to load those in EBCDIC from 1660 mag tapes :)
 
The inputs that way becuase the model was originally written in FORTRAN and wants FORTRAN styled inputs. An excerpt from the docs for the model:
"For accuracy of documentation each variable is described with both the FORTRAN read statement format (eg. [F10,1]) which defines the physical input limits, as well as an ‘assumed’ realistic input value limit (eg. (N5,3)) as derived from real data."
 
TIL that scikit-learn < scikit < scipy
 
There's a decent chance I'm misunderstanding the requirements, but
data = [
    [2007, 27, 3.9, 5.0, -3.0, 0.1],
    [2007, 28, 9.0, 7.3, -3.2, 0.0],
    [2007, 29, 10.7, 9.9, -1.2, 0.0]
]
data = [[str(item) for item in row] for row in data]
col_widths = [max(len(row[i]) for row in data) for i in range(len(data[0]))]
output = []
for row in data:
    output_row = " ".join(item.rjust(width) for width, item in zip(col_widths, row))
    output.append(output_row)
print("\n".join(output))
Result:
2007 27  3.9 5.0 -3.0 0.1
2007 28  9.0 7.3 -3.2 0.0
2007 29 10.7 9.9 -1.2 0.0
 
I'm going to format every thing as strings with something like "{0:.2}".format(1.234232) and use to_csv with space delimiters and see if i can get the format right. I'll let you guys know how that goes. LOL
Oh wait... I just saw your answer kevin, thanks. I'll give that a go. I can modify as needed
 
3:16 PM
I interpreted "consistent spacing" to mean "all of the columns must line up nicely, and I don't know how wide each column is ahead of time" but now that I read it again, "fixed width" probably means "I already know the expected widths of each column and they will never change"
I guess you can just stick those constant widths in col_widths in that case
 
seems too localized for me, and the dupe is good enough if we assume that askers actually learn the language and do some work
 
@W.Dodge
df = pd.read_csv(pd.io.common.StringIO("""\
2007 27 3.9 5.0 -3.0 0.1
2007 28 9.0 7.3 -3.2 0.0
2007 29 10.7 9.9 -1.2 0.0
"""), delim_whitespace=False, sep='\s{1,}', engine='python', header=None, names=list('ABCDEF'))

fmt = '{A:4.0f} {B:3.0f} {C:6.2f} {D:6.2f} {E:6.2f} {F:6.2f}'.format_map
with open('my_fwf.txt', 'w') as fh:
    fh.write(df.apply(fmt, 1).to_string(index=False))
 
Yes exactly. Its a combination of exact inter column spacing as well as exact decimal spacing where each column is formatted slightly differently. Fortunately there are only five. Thanks @piRSquared. You guys are a tremendous resource!
 
Actually, the above post was left closed in the reopen review queue stackoverflow.com/review/reopen/20541986
 
3:20 PM
btw, one of the benefits of @Jon being around lately is that I learned format_map (-:
 
@roganjosh wow
 
It was roundly, and rightfully, blasted out of orbit :)
 
I read the comment
 
That's not the original video (obviously); I haven't looked particularly hard but I guess it was redacted in the end, such was the backlash
 
3:28 PM
@piRSquared good to hear... was wondering what that lambda comment was about :)
 
I meant that I had written that dumb lambda so many times because I didn't know about format_map
 
sometimes it's nice that we can get a "TIL" moment :p
 
wim
3:54 PM
I used format_map once or twice
I forgot why it exists - is not just another way to do .format(**the_map) ?
 
To allow custom mappings (as in subclasses of dict)
 
@wim yeah... but directly callable and doesn't require the unpacking - doesn't support position arguments
So if you're only used named stuff... it's great
anyone else seeing MSO titles in red?
 
13
Q: Why is Meta Stack Overflow so...bright today?

MakotoThis doesn't seem right - the links are normally a subdued gray, but today they're red. What gives?

 
oh good... not me then :)
 
blood moon
and I thought my company was playing tricks on me turning my monitor's brightness up.
 
4:10 PM
MSO is awake, and it's angry
 
Ph'nglui mglw'nafh Cthulhu R'lyeh wgah'nagl fhtagn. ?
 
Ia! Ia!
 
btw... anyone here play "Golfs with Friends" - was thinking of getting that on Steam... the minecraft thingy didn't go too bad, and we've done some good ol' duke3d w/ @poke... might be a laugh
(or maybe putting up an MC server again - bit old now, but can be done... who knows)
 
I'd spend time on an MC server
 
modded MC for 1.12 came out a month ago, or was it 1.13 dont remember.
That golfs with friends was fun when I played with my drunk friends. I think I got like 10 hours of fun
 
4:17 PM
Rocket league is my go-to recommendation for anyone looking to waste time being bad at something
 
@MooingRawr you're not possibly implying that people who are sober play crazy golf? :p
I think - I might have the archive of the world from our old sopython MC thingy in Glacier somewhere...
starting again would be a laugh though
 
There's so much new stuff now that it might be worthwhile to just start over
 
come now, we are software devs, why would we want to go back to an older release when we can move to a newer one. :D also I played golf sober, I got entertainment not from the game but from my friends' mess ups
 
wim
@vaultah huh?
subclasses of dict will work fine with format/splatty-splat
Still not really understanding why to type 2 extra characters for the same thing, and also losing features in the process ..
 
4:53 PM
@wim I so need to get "splatty-splat" in an answer somewhere :p
 
5:04 PM
user image
8
 
Closing as opinion based
 
wim
5:32 PM
Aha
>>> d = defaultdict(int)
>>> d['k1'] = 1
>>> '{k1} {k2}'.format_map(d)
'1 0'
hmm, I think I knew that at one stage, but it was so useless that I forgot about it.
I see a PEP for two new magic method coming out of this: __splat__ and __splatty_splat__, which default back to __iter__ and __iter__-with-__getitem__ under normal circumstances. — Mad Physicist Jan 18 at 16:44
 
Good to know that my suspicion for the magics for ** was correct
 
5:49 PM
let's golf: given a list of strings, sort them and add distinguishing (increasing, starting at 1) numbers to any duplicates -- e.g. ['b','c','d','f','b','f'] -> ['b1','b2','c','d','f1','f2']
 
intredasting
 
What on Earth happened with stackoverflow.com/questions/56011/… to be closed as "not constructive"?
 
>>> [q for k,v in __import__("itertools").groupby(sorted(['b','c','d','f','b','f'])) for q in (lambda v: [k] if len(v) == 1 else [f"{k}{i+1}" for i in range(len(v))])([*v])]
['b1', 'b2', 'c', 'd', 'f1', 'f2']
 
DSM
"Is there a stylistic reason" -> "this question will likely solicit debate, arguments, polling, or extended discussion"
 
^
also, close reasons were not the same back then. I believe a contemporary closure would probably be opinion based (which it very much is)
 
5:57 PM
Shouldn't it be edited to ask whether there were definitive differences?
 
Double quotes are better because it uses more black pixels, and therefore your monitor uses less power displaying it.
 
(Exercise: determine five "well, actually..." responses to the above message)
 
But the answer to "Is there a stylistic reason to use one over the other" is just "no"
 
Well I've just seen it being used as a dupe
 
5:58 PM
@Kevin well, actually, most people use a white on black screen so the double quotes limitate the amount of black pixels
 
So it's closed as non-constructive and is being used as a dupe target
 
1. But what if you're using a white font on black background?
2. What if you're not using a monitor, but a continuous feed printer?
3. Modern monitors use the same amount of power for both light and dark pixels.
 
@roganjosh why not
 
DSM
sum([[k+(v>1)*str(i+1)for i in range(v)]for k,v in Counter(s).items()],[])?
Ehh, toss a sorted in there.
 
@roganjosh The topic is off topic, yet the answer has high visibility, so it's fitting to use it as duplicate target to the sempiternal other questions about these that will be asked
 
6:00 PM
@FélixGagnon-Grenier so we maintain a question with hundreds of upvotes and close other questions as a dupe of that, but call the question "non constructive"?
 
yes, exactly
the message that it is an off topic topic is clear, as in, newer duplicate questions are directed towards it
and everyone gets to know what was written in the gighly voted question
4 mins ago, by Félix Gagnon-Grenier
also, close reasons were not the same back then. I believe a contemporary closure would probably be opinion based (which it very much is)
 
I'll bow to public pressure. I think it's just the "non constructive" tag that I'm a little perturbed by but, as you say, it's renamed now.
 
If you feel about it, you are more than welcome to flag / mention the user who locked the post so that it can be reopened and then reclosed with a proper close reason... if you believe it's worth the trouble (which would totally be ok)
 
I think that reopen would die a death :) It's just a very early question, so I'm struggling to differentiate it from any discussions on PEP8
The code runs, why would PEP8 be considered constructive now...
 
Je suis PEP8
 
6:08 PM
@DSM nice
 
@roganjosh historical reasons (see historical lock). And duping new questions doesn't make them on topic. Using off-topic targets for off-topic dupes is fine.
 
>>> s=sorted;s(x+str(s(l)[i:].count(x))*~-l.count(x)for i,x in enumerate(s(l)))
['b1', 'b2', 'c', 'd', 'f1', 'f2']
Can still be golfed
 
wim
@roganjosh wow posts without the voting icons look really .. naked and weird
 
@vaultah scratch that, doesn't work for some inputs
 
wim
I was a habitual ' quoter and I'm still butthurt that black turns them into "
 
6:22 PM
Probably because you "can't" easily do this as easily with single quotes
 
wim
yeah I would use double quotes in that case
' is one key, " is shift + '
 
@wim I find the lack of CoC-compliant downvoting... disturbing.
 
wim
even python agrees
 
\o cbg, does anyone know if there's some magic function to set a default argument of a function to be the function name itself?
 
wim
>>> "abc"
'abc'
 
6:24 PM
I'm not so confident that there is a solution for this.
It's just I am writing a lot of functions that have a default argument in that pattern and I could be coming up w/ typos
 
wim
@OneRaynyDay no. use a callable class if you need that.
 
@wim So you mean something along the lines of:
 
wim
The function doesn't exist at the time that the default arguments are evaluated
 
class Foo:
    def __call__(self, args, arg=None):
        if arg is None: arg = type(self).__name__
pardon the bad variable names, but is this what you meant?
 
wim
Yeah
there is no "self" for a function. you could probably do some horrible hack with decorators (but I would downvote it with a vengeance)
 
6:29 PM
bleh, I'll take it :)
 
DSM
If we have functions we want to change the behaviour of, I'm not sure why decorators would be such a bad idea.
 
wim
A function that needs to know its name to work properly violates "keep data out of your variable names".
 
Okay, I did it:
>>> l = ['b','c','d','f','b','f','f']
>>> sorted(x+str(l[i:].count(x))*(l.count(x)>1)for i,x in enumerate(l))
['b1', 'b2', 'c', 'd', 'f1', 'f2', 'f3']
And you can save 3 bytes in Python 2
 
wim
bff <3
 
DSM
@wim: for me it depends on the purpose. If I'm adding it in to branch on it for control flow, yeah. If I'm adding it in for debugging purposes, l don't mind it at all. Intermediate situations get intermediate evaluations.
@vaultah: won't that fail if there are so many fs that the sort puts f11 before f2? ;-)
 
6:33 PM
@DSM noooooo
 
wim
For debugging, you could use inspect. I have a hard time imagining a debugging situation which would warrant a design where you want to use the function name in a default argument.
 
@vaultah I'm moving the hole, you can expect no more than 9 of the same string
 
DSM
Maybe I'm building some kind of flow of code nodes and I want the default name of a DataIntake class to be 'DataIntake' without having to retype it. (Replace with functions generating objects in this case.) It doesn't strike me as immediately crazy.
 
@MoxieBall haha, thank you :P
 
DSM
So kind. :'-)
 
6:37 PM
@DSM that's actually almost exactly what I'm doing
so at least I guess I'm not crazy
 
Cbg
 
DSM
@OneRaynyDay: not immediately. No promises about later.
 
@DSM I feel like python programmers don't fall into dementia as often as C++
so at least there's that
 
@vaultah I'm getting objects with the same name but different UIDs back from an API, and I need to display them in a list and be able to tell the difference between them -- there's only ever like 3 of the same name
 
(but then again I'm also writing C++, so there's that)
 
wim
6:42 PM
@DSM Hmm. Can you do that with less code than it takes to retype it?
 
and obviously I can't use a golf solution in production, but it seemed like an easy problem with an annoyingly lengthy solution
 
wim
Not that "less code" is better, but if there are 50 of these functions and not just 1 it's time to level up the abstraction.
 
DSM
@OneRaynyDay: It's hard to say. The Python programmers we see on SO are a strange mix of wizards and beginners who might be better advised to seek alternate careers, so it's hard to generalize from that.
@wim: probably not, characterwise. FWIW the closest example I have in any codebase I maintain actually leaves it as a manual ('object', Object) table and there's just a test to make sure there aren't any typos (it's a shared codebase and I have a strict policy of limiting cleverness there.)
 
00:00 - 19:0019:00 - 23:00

« first day (2854 days earlier)      last day (2108 days later) »