« first day (3149 days earlier)      last day (1782 days later) » 

7:00 PM
So no, don't "declare". In modern C you don't even have to declare at the top
 
user10984358
I didn't know you could add to tuple, thanks for that
 
It will rebind a new tuple to the old name
Rarely needed in nature
 
user10984358
so what I am taking home is no decelerations
 
user10984358
declarations
 
user10984358
I have to read the link posted here though
 
user10984358
7:01 PM
you guys are all talented lol
 
Declarations are a kind of deceleration because they make your code slower :-P
i = int; i = 1 is two whole byte code instructions longer than just i = 1
 
user10984358
I always thing certain things are cooler certain way but it turns out that they are wrong
 
user10984358
I usually do i=0 or I=0.0 for floats and int and only the objects for list and tuple, but yeah I get what you are saying
 
not "no declarations" its "use declarations when you need them (when it makes sense)" not just "because I need a variable or other structure"
 
user10984358
when does it make sense??
 
user10984358
7:04 PM
if I am documenting then I wouldn't need it, would I??
 
Here's an example where "declaration" makes sense:
#find the sum of all numbers from 1 to 10... Without using sum() for some reason
total = 0
for i in range(10):
    total += i
print(total)
 
or (just using the same statement I make for Java & C++ courses I teach): "Make local variable declarations as close to their first use as possible not necessarily at the top of the function/method". If it does not make logical sense to declare a variable (like when using certain elements of Functional programming) then don't
 
Delete total = 0 and this code will crash
 
user10984358
how did I not think of this
 
user10984358
I used to do the same with lists until I found out list comprehension
 
user10984358
7:06 PM
a.append(x)
 
@TheNamesAlc As Andras said, you can't really add to a tuple. It just creates a brand new tuple object and destroys the old one. So doing fake declarations like a = tuple() wastes time & creates more work for Python's memory recycling machinery.
 
user10984358
@JGreenwell this!! I tend to kinda do this, declare when I will actually be manipulating them
 
I use the Google Style guides for most of my teaching - they can be a great place to start if you want to get an idea what its like to program for a company (and why my answer to most questions about style are "whatever your boss says")
 
@TheNamesAlc OTOH, it can be a good idea to use a docstring in your function that explains what each arg is for, and what type(s) it's expected to be. And also document what gets returned. And you might like to add a comment in the code for each important variable when it first appears, that explains what that variable is for, although it's much better if you give the variable a sensible name so that no explanation is necessary.
 
^ what I meant by "use documentation" :)
 
user10984358
7:12 PM
a=tuple()
someList=[1,2,3]
for i in someList:
a=(someList.index(i),someList.index(i+1))
if(someList.index(i)==0):
break

print(a)
 
Of course, if you use type hinting, you don't need to document the types in the docstring. But I'm not into type hinting. ;)
 
user10984358
not a practical scenario but I am not declaring that tuple a over there, will a still be accessible outside
 
user10984358
also forgive my horrendous indenting, I am not used to this chat
 
@TheNamesAlc In Python, a for loop doesn't create a new scope, so a will still be valid after the loop finishes.
 
user10984358
I will just change my habit, use docstrings and other new things I learned here
 
7:14 PM
That's a great example of code where you can go ahead and delete a=tuple() and it will still work fine
 
user10984358
this whole snippet (the original is different but you get it) was what that made me ask the question
 
@TheNamesAlc Please don't do that. It will just make your code less readable if you use p() as an alias for print()
 
I wonder how many programmers there are out there that make their variables one letter long so they can code faster, but never learn to touch type
 
user10984358
@PM2Ring lol, since I dont really use IDE's I just stick with manually printing all variable values so I am stuck with a lot of commented print() lines, but yeah I mustnt be doing that
 
user10984358
what's touch type??
 
7:19 PM
Typing without looking at the keyboard.
 
user10984358
is that what typing is sposed to be??
 
user10984358
isn't *
 
lol, when I'm working on a contract or course at home and my wife starts talking to me - she gets really, really annoyed at more for continuing to type as I talk to her :P :)
 
user10984358
the verb remains the same but shouldn't typists not look at the keyboard when they type
 
You make it sound like you've never seen anyone Hunt & Peck before, which is surprising to me, because around here that's the default unless you go out of your way to learn how to type properly
 
user10984358
7:21 PM
I do look at my keyboard when I type but I wouldn't call that typing
 
user10984358
I just type but its not "typing" in my books at least
 
user10984358
ohh the two finger ones I see them a lot
 
user10984358
some of my classmates do that
 
{coworker_3} was somewhat disconcerted this afternoon when he asked me, "hey, can you write a Python script to..." and I was already typing out a prototype of what I predicted he wanted while making direct eye contact with him
 
user10984358
probs because of more time of phone than on a laptop or pc
 
7:22 PM
two finger typing has long preceded the era of smart phones.
 
user10984358
@Kevin I want to do things like these
 
user10984358
what do average at?? 60+ wpm??
 
yeah, I don't see it more with CS students (same number as always really) - do see it a lot with the math or bio students who take a programming elective
 
The last time I did a typing test, I got...
Apr 17 '18 at 16:35, by Kevin
@ZackTarr Let's see. I just did three rounds on https://www.keyhero.com/free-typing-test/, and got 67.19, 98.28, 84.00 WPM for each of them respectively
 
user10984358
golly
 
7:24 PM
My WPM when coding is slower because I can never remember where the parentheses are
 
user10984358
I can average 50 I guess that too if doest have special words
 
user10984358
I know parenthesis but that it
 
user10984358
@JGreenwell what do bio students learn ?? they'd benefit more from simulation courses dont they??
 
user10984358
I suck bad if I type at anything but my laptop
 
....they learn how to program...the same as everyone else
You might be shocked at how much coding scientists do
 
user10984358
7:26 PM
do they have the same curriculum as that of the cs ones??
 
I am proud to say that I have increased my typing speed by about forty percent since I began coding, which is sad because I am still quite slow. I have learned to type and code simultaneously.
 
no, hence "elective"
 
user10984358
the first thing that comes to my mind is forming bonds on a pc lol
 
user10984358
@Dodge mind recommending you ways??
 
I recommend countless hours of IRC daily starting at the age of 12
 
user10984358
7:28 PM
my typing has actually degraded, ever since I started using a Mac, I just type and it autocorrects so now I have learnt to not think of spelling and skip and words and still get a decent autocorrect rate
 
Dec 13 '15 at 3:17, by JGreenwell
Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live. Code for readability. - love that quote
 
user10984358
lol, when I was 12 I was playing games that too with arrows
 
Type as if you're racing with another guy to make the same obvious joke and only the one who submits first will get the gold star
 
I stand by that quote - its most true when your the one who ends up maintaining your code
 
user10984358
@PM2Ring I usually forget what I typed after a month, so I made it a habit to name actual variables and comment wherever possible
 
7:30 PM
Good habit
 
@TheNamesAlc Force yourself to not look and be okay with being slow at first
 
user10984358
I was one who named something like var1 var 2 damn those school MCQ's
 
user10984358
@Dodge how will I amp it up??
 
I learned to type on a clunky old mechanical typewriter that once belonged to my grandmother. I guess it was made in the 1940s, or maybe older. Touch typing's not impossible on those things, but it's not as easy as it is on modern keyboards. I do use most of my fingers when typing, but I never learned to touch type.
 
user10984358
how much is the increase from 3 fingers to 4??
 
user10984358
7:33 PM
6 to 8*
 
user10984358
other than enter I guess I uses 3 on both hands
 
user10984358
so I use 6 fingers
 
user10984358
will that double my speed if I use 8 fingers ??
 
en.wikipedia.org/wiki/Typing indicates that there isn't much of a relationship between your typing speed and the number of fingers you use.
More important is consistently using the same finger to press a particular key every time, and not moving your hands much
> We were surprised to observe that people who took a typing course, performed at similar average speed and accuracy, as those that taught typing to themselves and only used 6 fingers on average
 
user10984358
thats investing
 
user10984358
7:35 PM
intersting*
 
user10984358
I thought they were proportional, it made sense in my head
 
oddly enough, I had someone get really mad where I worked recently because I named a variable "mdn" & one "M" in a function (math people, shhh) literally shouting at me cause "how are we suppose to know what that does?!"
 
I do think there is at least a weak relationship, since it's easier to keep your hands from moving much if you make use of all your fingers
 
user10984358
I still dont use uppercase as starting though I believe python allows that
 
He felt bad when I reminded him my job (atm) was just to add documentation and pointed him to the docstring at the top of the function which said "mdn = median, standard notation. M = mean, standard notation." and the change log which had my notes stating "added documentation for various functions, added recommendation for variable name changes for readability on functions not owned by ME".
 
7:37 PM
If you're really interested in getting the absolute highest wpm possible, I think it would be worth the effort to learn to type the formal way
 
user10984358
it just seems odd
 
user10984358
typing q with some finger you are not used to
 
(which is not to say that there is a formal way of learning to type, but rather that there is a formal way to type and that you should learn it)
 
user10984358
I have seen courses
 
user10984358
phones have ruined typing tbh
 
7:39 PM
I felt bad cause I agreed with him
 
user10984358
with autocorrects and the swipe to type
 
I went to school in the days of Nokia bricks and I can confidently say that people have always been terrible at typing.
 
user10984358
for some who needs things done, I would be angry if I didnt get to know what M meant in a code
 
@TheNamesAlc Sorry got distracted, amp it up you ask? Not sure. I can say that learning to switch windows, apps, and work spaces from the keyboard will make you feel fast even if you are still slow.
 
user10984358
so did I
 
user10984358
7:40 PM
@Dodge yeah, screen space in Mac has improved my productivity a lot
 
BTW, @TheNamesAlc You can edit chat posts for 2 minutes. The quick way to get at previous posts is to hit your up arrow key.
 
user10984358
ohh just like a command line
 
user10984358
:)
 
Yep.
 
user10984358
I kinda liked the press 1 three times for c type mode
 
user10984358
7:42 PM
whats it called??
 
in this case there was a different sample and population so my recommendation was to name them "sample_mean" and "sample_median" in function then "population_mean" and "population_median" in main (but it was checked out so I couldn't edit that part when I was doing documentation)
or I could but my changes would likely get overwritten during merge
 
user10984358
if I have an unusually long variable name, I just do this

unusuallyLongVaraible=3.14141414141
t= unusuallyLongVaraible
 
user10984358
I use t else where and when I am done I find and replace t
 
IDEs make me not care about variable name length anymore (by the time I type 3 letter I just select it from the list) - better to be descriptive
 
user10984358
you get a pencil mark if you edit?? thats what it meant
 
7:45 PM
and I use a plugin for autocomplete for Gvim so not a problem in basic editor either (or ctrl+n...ctrl+p? one of those)
 
user10984358
talking about means was it anyway related to central limit theorem ??
 
user10984358
thats the only place where I have heard of these two means
 
user10984358
took a basic course in data science
 
user10984358
very basic acc to standards in other uni
 
@JGreenwell I think it's perfectly fine to use the traditional 1 letter names when implementing maths or physics formulas. So if I'm doing an orbit sim, I'll use G for the universal gravitation constant. But I'm likely to use radius or rad instead of r, and mass instead of m. OTOH, I might do m_earth and m_sun, etc.
 
7:47 PM
yeah, this one wasn't "traditionally" math based place though - me and other guy were only two "math" people :)
 
@JGreenwell Tricky. I think you chose the best course: improve the documentation, and suggest improved names.
 
user10984358
does it really matter if you type like so and so
variable_numero_uno or variableNumeroUno
 
user10984358
I for some reason dont like using underscores in variable names, though I believe the standard in c++ was like that??
 
@TheNamesAlc In Python, we prefer snake_case for simple variables & functions, and CamelCase for class names.
 
user10984358
I just use camel case for everything
 
user10984358
7:50 PM
should I tend to move from that??
 
user10984358
though in my case it would be camelCase, idk what I am following
 
yeah, half my work when I get a contract seems to be asking the question "where is this documented?....oh, nowhere?....*sigh* let me make some documentation.".
 
@TheNamesAlc You probably should. It will make it easier for people used to the normal Python convention to read your code.
 
@TheNamesAlc that's Java (and sorta by extension Javascript)
 
user10984358
I picked it up when I was trying to learn swift
 
user10984358
7:52 PM
I was watching a video by mark price from devslopes
 
user10984358
subliminal effect I guess
 
@TheNamesAlc There are a couple of places in the stdlib that use that convention, but that's because the code was ported from another language (Java, IIRC).
 
Check out a style guide for Python - it can give a lot of guidance - and always refer to the style guide
but honestly, once/if (as I don't know why you code) you work for a company there's always variance
 
user10984358
I code because I am a student
 
user10984358
I will be joining as an intern soon
 
7:55 PM
Also, if you're adding code to an existing codebase that uses a different convention to the usual PEP-8 style, then you should use the existing style. Unless you plan to re-write the whole codebase. :)
 
user10984358
as an intern I am pretty sure all I get is test this and test that
 
restate: I don't know what industry you will be using your coding skills in (but corporate or intern will definitely want to learn to read a style guide)
and change these variable names, add some documentation, this needs to be a different color, etc...
 
user10984358
lol probs those as well
 
user10984358
last intern I was in I was tasked with doing ppt's
 
user10984358
most of the time, I did this stupid php intern which I regret
 
7:56 PM
or "we didn't want to pay for a full coder so taking a chance with an intern doing full developer responsibilities" (I've seen all these)
 
user10984358
that is exactly what an intern should be defined as
 
user10984358
if its media companies you get to buy coffee
 
user10984358
if its coding you get to do docs
 
user10984358
at least I hope this time it will be different
 
user10984358
they said I might be suing python thats why I hopped in to python
 
7:58 PM
what the last one I said? oh, no x 255
 
user10984358
yeah, at the end of the day its a win win for both of us
 
user10984358
its a huge win for the company but still a win win
 
user10984358
I get paid, they get work
 
not because you have no skill or no intern has ever been ready to just jump in - but yeah, I've seen that and it gets bad - really bad - like whole server farm down type bad
 
user10984358
lol
 
user10984358
7:59 PM
they know i need that internship so bad
 
user10984358
cant really say I wont do this unless you give me this
 
user10984358
for all I know I really wish they just wouldn't let me barge in and say "person x did this I want you to continue what he did"
 
user10984358
this is what I hate as an intern, you dont get full freedom, you have to either change what someone wrote or test someones code
 
read the style guides, build a project for yourself (I like building backend parsers & APIs to learn languages myself but everyone is different there), and then look on github to see if you can "change these variable names, add some documentation, this needs to be a different color, etc..." on so projects for practice is the only advice I can give
 
user10984358
I am recently working on a very small thing using selenium
 
user10984358
8:02 PM
its just a 15 work if you have the time for me it takes a while
 
user10984358
thanks for advice, I just dont have an idea atm
 
user10984358
thats why I was thinking of going with selenium
 
user10984358
go to googlefeud.com
 
user10984358
I am just trying to automate the game so I can get real time results and get a high score lol
 
user10984358
I stopped working on it two days ago cuz I reached my monthly data cap and pages take an eternity to load now
 
user10984358
8:04 PM
so i am waiting for my connection to reset this month
 
user10984358
alright everyone been a nice exchange, I have like 5-6 tabs open from the links y'all sent me, gotta go through them.

have a lovely day y'all.
 
8:17 PM
New hobby: Reading this person's answers
 
8:29 PM
cbg
 
wim
@Kevin dict.setdefault is the closest I could think of
 
8:41 PM
@Aran-Fey I've seen some of those before. I've even upvoted (at least) one of them.
@wim I love dict.setdefault, but it returns the value, not the whole dict, so it's in the same category as .pop and .popitem
 
I just discovered something neat, so it's puzzle time:
# Fix the `foo` function without assigning a value to `x`!

def foo():
    ...  # YOUR CODE HERE

    def bar():
        nonlocal x
        x = 3

    bar()
    print(x)
 
Hmm hmm
 
the other way 'round: (url "title")
 
Thanks
 
ha, no :P
it's still a syntax error :P
 
wim
8:51 PM
@Aran-Fey yeah, I apparently encountered a few of those (already downvoted). language is bizarre.
 
Is it? I find it quite funny O.o
 
wim
I find it annoying
just put the important content already and cut out all the extra fluff
@PM2Ring true
the question is - why do you need the thing returned, when you were the one that passed it in the first place?
you already have a reference to it.
 
@Aran-Fey hm. any hints for this one? where do i begin to look
 
@Aran-Fey Stumbled On but I know not why.
 
@Aran-Fey I think it's amusing, but I think I'd get sick of it rather quickly. It'd probably be fine on xkcd, but it doesn't fit the tone of SO.
 
8:58 PM
@ParitoshSingh hint
 
hmm, my thing didn't fix foo... nvm
 
what even, this is so bizzare
 
@piRSquared Huh, that's interesting. But yeah, foo is supposed to execute without crashing.
 
ding dong!
 
wim
9:03 PM
@Aran-Fey what do you mean by "fix"?
 
I don't like it. I mean, I like it because TIL... but I feel dirty
 
wim
just resolve the SyntaxError?
or does it actually have to print something when called
 
yeah, it has to print 3
 
@wim you have to be able to execute foo()
 
"without assigning a value to x" and yeah, it needs to run. the spot where you can make changes is the only place to write.
 
wim
9:06 PM
not sure if cheating, seems too easy
 
:(
that's the intended solution, yeah
 
You followed the instructions.. so yeah
 
wim
I wonder if there is any solution in Pythoff
 
@wim btw Pythoff
 
"Pythoff is safe and non-toxic" Is it really?
 
wim
9:12 PM
Pythoff is not compatible with hydrogen peroxide or beneficial bacteria.
beneficial bacteria? what?
 
bacteria that benefits you
 
wim
is the kerning on that website totally jacked up for others, or just me (chrome on linux)
 
I wouldn't say "totally jacked up", but it's a bit difficult to read, yeah
 
wim
oh, there can be no solution in pythoff because you don't have nonlocal anyway. duh.
 
@wim it harms your intestinal flora
 
wim
9:20 PM
curious - this seems to work for O.P.
 
geez, does pythoff actually have any features? No nonlocal, no keyword-only arguments...
 
wim
is that actually possible? I thought the datamodel does not allow it at least not CPython
 
@Aran-Fey It has the feature of making unicode exciting
 
wim
@AndrasDeak hah
 
well, I suppose...
 
wim
9:22 PM
I also like the "no implicit namespace packages" and "no type hints" features
 
no walruses
 
3.7 can do that too...
Hmm, type hints since 3.5
 
@wim Yeah, no, that doesn't work
Obvious solution: a.__class__ = type('A_with_getattr', (A,), {'__getattr__': new_getattr})
 
wim
9:52 PM
hmm, OP wrote "in my actual implementation, I cannot modify the definition of the class A"
maybe that was a lie ..
shame the dupe doesn't link to the datamodel docs
 
10:38 PM
rbrb all
 
11:12 PM
Hi guys
I have a column called Actors which has 1) Sam Worthington, Joseph phil, Andrew tiffin, Philip hall 2) Brue wills, theis win, Arnold kim likt this I have 1000 rows.. I want to get only first two actors name and store in two different column names.. Example: Sam Worthington in one column and Jpseph Phil in another column..
 N = 2
L = [x.split(',')[:2] for x in df2["Actors"]]
df3 = pd.DataFrame(L, columns=[f"Lead_actor_{i+1}" for i in range(N)])
df2 = df2.join(df3)
return df2
I have created this code and it's working fine.
df2 is my orginal datframe..
I want to create a function and pass it other columns through apply function. Because I got close to 20 columns like this.. Could you please help guys how to create a user defined function?
 

« first day (3149 days earlier)      last day (1782 days later) »