« first day (3514 days earlier)      last day (1427 days later) » 

12:37 AM
In case anyone was curious: stackoverflow.com/questions/22571267/…
(basically what Andras said)
 
 
4 hours later…
5:08 AM
Is there any more optimal(in terms of times) to do this:
from itertools import product, permutations
#moves is a list of list
queue = list(product(*moves))
for i in range(len(queue)):
	current = queue.pop()
	tempC = list(permutations(current))
	#code
*time
 
 
2 hours later…
7:01 AM
Hey guys... Our college is hosting our annual flagship tech fest and we have been tasked to publicise it on all platforms. Is it a good idea to post it as a question?
 
No, questions are questions, not advertisements
 
Hmm... Thanks :)
Well, then how do I go 'bout it?
 
7:50 AM
Hi
Last time when I was logged in to the forum, the guys recommended me:
[black](https://black.readthedocs.io/en/stable/installation_and_usage.html#command-line-options) .

Can anyone write me what is this black and how can I use it when I write github gists?

Thanks.
 
8:15 AM
i need to return a filtered string which i have tested this does
but i when i run it on the tests
i get ~ no output~
0.1,0.3,0.5,0.7,0.9 this is the test but when ive tested the function manually it works
 
Your if __name__ ... check is inside your function
 
omg thanks
sorry
 
@YoelZajac Erm, you've been linked to black's documentation. Doesn't that provide enough information?
 
Not enough (for me...). I need some extra help in installation and using it in github gists. Does it have a separate page with wider explanation? I would be happy to get a link.
where do I write pip install black ?
 
8:33 AM
Open up the terminal, or if in Windows, PowerShell. If you haven't installed pip yet, type python get-pip.py and then type the above.
 
ok I'll try. Thanks.
I found this where I can download black anyway...
 
Hello
 
Won't apply for every package.
 
Is there any way to take python tkinter scrollbar thickness
?
 
ValueError: could not convert string to float: 'Some random non floating inputs'
ive googled that error but it doesnt come up
anyone have any ideas?
 
8:44 AM
do you used casting?
 
points = list(map(float,data_str.split(',')))
 
a = "1.36"
print(float(a))
 
^^^
 
float('Some random non floating inputs')
catch the exception and deal with it
 
oh
@Aran-Fey thanks
 
8:50 AM
width

Width of the scrollbar (its y dimension if horizontal, and its x dimension if vertical). Default is 16.
@Permian You need to only google "could not convert string to float".
 
i did!
 
It's telling you that you cannot convert a string to a float because it has non-integer items.
 
my code doesnt execute within the time limits. ive changed the collections dict from list to set but that didnt affect the outcome
as far as i can see my code is O(2n)
 
You just said your problem was string to float?
 
@JossieCalderon that problem was solved by @Aran-Fey
i cant see how i can make this more efficient
 
8:57 AM
no need to tag him, mate
 
ok
 
the only improvement I can think of is to not recalculate tmp for every val. You'll see the same value multiple times and redo the same calculation for each of them
 
interesting
ill try this now
ive completely broken my code now haha
i removed the function call to abs becuase i think calling functions would slow it
 
9:14 AM
actually, I just realized that the value you're calculating there isn't the same all the time
 
i just cannot see what im doing wrong
i cant see why that breaks, i thought it i tried to save the precomputed vals it would save time
but now it just breaks
 
9:50 AM
How may I convert the list ['\r\n\t\t\t\t\t\t\t', '\n', 'mytext1\r\n\t\t\t\t\t\t', '\r\n\t\t\t\t\t\t\tmytext2\r\n\t\t\t\t\t\t'] to [mytext1, mytext2]?
 
10:00 AM
Well I wrote `pip install black` on PowerShell. It writes me several lines which all start with `Requirement already satisfied`.
Does it mean that it's already installed?
 
@JossieCalderon You can strip the whitespace with .strip() then you just need to filter
 
@YoelZajac Yes
@Peilonrayz OK
 
Thanks
 
@YoelZajac take the time and actually read all the lines...
It's written in English
 
pip show black verifies installation
 
10:07 AM
Not reading errors and other output is the bane of programming
"I get an error". Well perhaps the error tells you that parentheses are missing in print x.
 
Of course it's written in English, but it's not a story and it's pretty difficult for those who make it the first time (me...)
 
@YoelZajac I'm telling you to read it exactly because you're new
You don't want to ask here each time you use pip, right?
 
@JossieCalderon context?
 
God = The programmer. Margaret = the computer
 
10:09 AM
Ah...
 
10:24 AM
the length of the test case is 99984
 
@Permian new problem?
 
i cannot see how to improve the efficiency of my code as it already looks efficient
 
Ah, no
if len(arr) > 10**5 or len(arr) < 1:
    return -1
 
those are the constraints
 
still that piece of yam
@Permian I know!
You're going out of your way to learn wrong
 
10:29 AM
the only line that looks slow is tmp += (j-element) if (j-element) >= 0 else element - j
 
which is your problem but we'll have to clean it up eventually
 
just a hint please
 
abs
 
that means calling a function
which is what i did originally but had the same problem
 
Profile your code like a professional
 
10:31 AM
im not a professional lol
using some timing library?
 
@Permian Sets can be really slow, I can't see why you need it here. Have you tried timing your code when using a list?
 
yes same problem
i thought set is o(1)
but list would be o(n)
 
ok... black is installed, but now I want to use it (integrate it?) in gists.
I look [here](https://black.readthedocs.io/en/stable/version_control_integration.html#) , don't know if it's the right place to look at. I would be happy to get help.

I looked also [here](https://black.readthedocs.io/en/stable/editor_integration.html) , but I don't think that a gist is an editor.....

Maybe [here](https://black.readthedocs.io/en/stable/the_black_code_style.html) ?

Thanks a lot.
 
I think there is a way to speed up the calculation of tmp after all. Say instead of a set of indices you have a sorted list of indices [a, b, c, d, ...]. You calculate the value for a as you do right now - loop over the whole thing and sum up the distances. But when you calculate the value for b, all you really need to do is subtract (b-a) * number_of_elements_after_b and add (b-a) * number_of_elements_before_b
Or something along those lines anyway
 
ok
cool
 
10:36 AM
@YoelZajac black operates on files, not on gists
 
@Aran-Fey So I have a file which I open with Notepad++ .
I'm looking here
 
@Aran-Fey but its not number of elements i want, i want to distance which have to be calculated
dont worry
 
Right, but you've already calculated the distance for a, and that lets you calculate the distance for b more quickly
 
still don't understand how to integrate black and Notepad++
 
@Permian I suggest asking your friend google about profiling python code. You'd probably need a line profiler.
 
10:45 AM
the distance for a is a-a + b-a + c-a + ... and the distance for b is b-a + b-b + c-b + .... The difference between b-a and a-a is the same as the difference between b-b and b-a, etc
 
surely you would need a hashmp to store those pairs though
 
you don't need to store them at all
you just need to know how many of them there are
 
im going to have to think about this because it isnt apparent to me at all
but i htink youre on the right path
 
Good job, Aran
 
@AndrasDeak Where can I read and understand where can I integrate Notepad++ files with black ?
Thanks.
 
11:01 AM
Er...that's just import black
 
You don't import black, you run it.
@YoelZajac why are you pinging me with that? Do I look like a search engine?
 
Hmm, that's odd. SearchEngineAndras has encountered an error.
 
Tried to search actually. Black with notepad++. Got nothing except dark mode of notepad++ .
 
You should look at the source, and if that doesn't help, and googling doesn't help, raise an issue with them. I don't know what "integrate with notepad++" exactly means, so I can't tell if what you're asking makes sense.
 
Notepad++ is an IDE. It's not specific to black.
 
11:08 AM
I get that. But how does an "IDE integration of black" work? I wouldn't expect black to be able to format your code on the fly. If it can do that, it should be clearly obvious from their documentation.
perhaps it can be integrated just like git, which is also something I have no information about
 
Is anyone here familiar with firebase paths for cloud functions?
 
@JossieCalderon you should read it for them too while you're at it
 
@JossieCalderon Thanks.
 
hey, is this sort of back and forth on a question typical? I feel like at this point I'm doing the work of a typesetter for this guys graph...:stackoverflow.com/questions/62099211/…:
 
cheers @AndrasDeak
 
no worries
 
>>> subst = '\ntext\r\n\t\t\t\t\t\t'
>>> myStr = '\r\n\t\t\t\t\t\t\t'
>>> myStr in subst
False
 
don't use camelcase if possible
you have 7 tabs in myStr but only 6 in subst
 
Yep...
 
user13004974
12:03 PM
Hi guys
i have a one python script now i'm able to run this then need to enter some value like :
enter file name to create: string.xml
enter input language = en
enter output language = ar

so folder create of "ar" but string.sml file not created
anyone help me please how to pass my string.xml file into script and return translated string.xml file

here is my script: https://paste.ofcode.org/knnRJVPw33tip5Y2FSeV3q
 
user13004974
@LinkBerest yes this is a python script
 
user13004974
12:21 PM
0
Q: How to run a python scipt and create a string.xml file for translation

Pranav BhattI have a python script now I'm able to run this now so here i need to enter some value like : Enter file name to create: string.xml Enter input language = en Enter output language = ar So folder create of "values-ar" but string.xml file not created anyone help me please how to pass my string....

 
12:46 PM
Feb 26 at 18:34, by Andras Deak
@JossieCalderon They don't have to come back with a bounty. And it's alright to ask here only. The problem is asking here and on main in parallel. You can leave moderation to regulars and room owners for now.
the last sentence still applies
 
I need to build some images for a report. Images are built with rectangles with circles and some dimensions. What library should I use?
 
try pygame @echefede
Its quite simple to use and you can draw various shapes
 
Hello Guys
 
1:01 PM
Thanks @rishi
I'll try it.
 
Today is a historical day. The US will launch astronauts into space after 9 years
 
wim
1:21 PM
Uh, haven't they been going up on soyuz every year?
The ISS is permanently manned I thought
 
The US sent in 2011 humans the last time
It cost around 500m to sent a shuttle to space. Crew Dragon will only cost a fraction of it
 
wim
No the US was still sending astronauts but using Soyuz rockets
It's great what SpaceX is doing but it's not like there has been no space travel since the shuttle was retired
 
2:02 PM
I'll start being excited when someone puts people on the moon again
 
Lets hope Starship will be constructed. The things keep blowing up one after another. SN4 burst into a fireball yesterday.
 
wim
@AndrasDeak been there, done that :) I'm more excited about starlink!
 
2:22 PM
Starlink will be able to service people on remote places but in big cities like Paris i believe they cannot squeeze so much bandwidth into a small satelite. Dunno.
 
2:33 PM
@ExoticBirdsMerchant Looked like it was an issue with the methane/oxygen supply plumbing to the rocket on the test stand, rather than an issue with the rocket itself. It had just done a successful static fire. Then gas leaking from somewhere on the ground, then flame starting also on ground rather than rocket.
@ExoticBirdsMerchant What about a thousand sats over Europe at once?
 
Maybe he can split the load to a network of more Starlink satelites. His saying about Starlink is it actually makes life easier for big Telcos and does not put them out of business. Think is i do not have relevant knowledge to assess exactly if that is possible.
I didnt knew that there was a problem with the launch pad eeeee launch rack. Thats good news. Thank you
 
@wim the space junk and astronomy concerns make me uneasy about that.
 
2:57 PM
Is there a better way to write this function, which returns an integer if we pass n=1, else returns a list
def f(n):

    l = [1]*10
    if n == 1:
        return l[0]
    else:
        return l
Or should the function always return a list, and the caller can decide if he wants the entire list, or one value if the list if of size 1
 
wim
personally I avoid inhomogeneous return types
you want the return types to quack the same way in practice, when they don't (and int/list certainly don't) it just means the caller needs to type-check the return before doing anything with it
so yeah, always return a list here (even if empty or 1-element list)
 
Yes, and I find them harder to add type annotations as well
 
wim
f = [1].__mul__
 
So if the value of l is passed to one function which takes a int, or another which takes a list, the type checking fails, since here f would be annotated as Union[int, List[int]]
 
3:14 PM
The libraries I use return homogeneous types unless explicitly requested otherwise.
 
wim
Haven't much experience with typed Python code tbh. I've seen how annotations are useful in frameworks like fastAPI, but using annotations just for the sake of type-checkers I'm still not really convinced about (seems like a lot of extra "busy work" for not much benefit)
 
I quite like type annotations for writing tricky code, especially if you refactor it a lot.
 
Thanks folks for the inputs
 
@wim I find being able to ctrl-b (find source) something I don't know and reliably getting the source rather than a 404 to be rather compelling.
 
Mostly, typing helps to avoid writing impractical chameleon code – like functions sometimes returning int and sometimes List[int]. If it is complicated to annotate, it is probably not a good idea.
The type checkers are hopelessly outclassed by what Python can actually do, though.
 
3:25 PM
@MisterMiyagi IIUC, Union in a return type won't work in such cases, if the returned value is further passed to one function which accept an int, and another which accepts a List?
Because the type checking is static, and it isn't actually executing the python code to be smart enough to see if int would be the return type, or List[int], based on the value of n in my case
 
You would need @overload for that.
You could define def f(n: Literal[1]) -> int:, for example.
 
@MisterMiyagi Does that mean n can only take value 1, in which case return an int?
 
That's why you need @overload, to add the other path.
 
@MisterMiyagi typing.overload says that the argument should be of different types, but in my case, n is always int, so will that be applicable?
 
And to make it clear that the function is hopelessly overcomplicated.
7 mins ago, by MisterMiyagi
The type checkers are hopelessly outclassed by what Python can actually do, though.
@DeveshKumarSingh see ^
 
3:31 PM
Agreed, and that's why we have things like Any, and cast
 
Ugh, no, that's why we should just use a single def f(n: int) -> List[int].
 
Python was designed to be a dynamically typed language, and type checking will always run into issues when it's outclassed
 
I don't see that as the reason. Type theory has dependent types and such, which would be able to handle that.
 
I am planning to stick to that, and if changing the function while adding type annotations is frowned, I will just stick to Any
 
Mostly, Python's typing is modelled after Java-like OOP, which just isn't Python's OOP model.
3
 
3:37 PM
Yes, I only have some working knowledge of these things, so some of my understanding might be flawed
 
For reference, if both a list and int return type are desired, I'd recommend splitting it into two functions. def f() -> int: and def fs(n: int) -> List[int].
 
That's a good idea as well
I had another question, hope you don't mind me asking @MisterMiyagi
 
wim
@MisterMiyagi but what if you already avoid that anyway, because you would not naturally code like that in the first place?
Seems kind of like “bumper bowling” if you need a type checker before you can recognize a clunky API or not
 
3:55 PM
For more context on my question, I am trying to add type annotations to an open source library, and it has always been confusing to me to find a balance between modifying bad code which causes type checking issues, or just somehow annotate them using Any, cast, assert etc
 
@wim If you already write perfect code, there is absolutely no advantage.
I've found out that I don't write quite as perfect code as I thought I would. ^^
@DeveshKumarSingh If you're using Any, you might as well not use typing at all.
 
@DeveshKumarSingh When I added typing to nox I used Any and # type: ignore. It now uses mypy --strict and it's easier to then go back and fix the stop gaps.
 
Using typing with Any is like being a vegetarian who eats meat.
 
That's a good analogy, I also avoid using Any
 
Which library among 'pytest' & 'unittest' is better for unit testing in Python 3.8.0?
 
4:09 PM
There is no such thing as a "better" library; they each have their own- just kidding, it's pytest
 
4:44 PM
unittest is a module in the python standard library, whereas pytest is a third party module
Either can work for you, based on how simple or complex is your usecase, though I personally prefer pytest
Also, as per pytest docs , it can run unittest-based tests as well
 
5:09 PM
Isn't unittest overly influenced by Java too? Or am I getting mixed up with the logging module...
@echefede I wouldn't advise using pygame for that. The pygame library is focused on interactive graphics for games. You can do static graphics using Pillow, the modern fork of PIL. You could use Tkinter, which is a standard module in modern Python distributions, but Tkinter is focused on creating GUIs, not standalone static images.
 
@PM2Ring the naming convention smells a bit of it... isn't it based on JUnit or something?
 
That rings a bell.
@AndrasDeak I can think of several Americans that NASA should send to the Moon. Unfortunately, NASA would probably try & bring them back to Earth afterwards...
 
heh
 
5:50 PM
This is my original date formate e.g ` 4 Mar 2020` as a string in my data set in one of the column names as `nav_date`. Now I want to sort the data using this `nav_date` column. so I did use the following code
link: https://pastebin.com/D04GuXHt

The result is sorted data but I lost original string formate for `nav_date`
and got this formate `2020-01-02`, so how can I get back that original string formate in my dataset?
 
6:11 PM
@AnilSarode create the converted column as a new column, not overwriting the old one
then sort on the new column, and optionally remove the new column
or just keep the converted column as a Series, argsort it, and use that to reorder your original df
 
6:58 PM
@AndrasDeak Thanks a lot for both the methods. I found the first one easy and less complex.
 
7:20 PM
cbg-evening
Hope things are good at your end
Got a quick question: I'm trying to do the following
Actually, just by typing my question, it acted as a rubber ducking.
Thanks guys
I drop the question anyway, just in case it helps someone with the answer
from random import randrange
for val in randrange(6):
    print(val)
Why it is not working. Because I forgot the range
for val in range(randrange(6)):
this one does the job. : )
 
7:58 PM
Hi I'm trying to do the following.. but it's not working as intended. Where am I messing up?
m = {'Pizza' : ['Cheese', 'Pepperoni']}
inv_map = {v: k for k, v in m.values()}
print(inv_map)
This results in:
{'Pepperoni': 'Cheese'}
Whereas I wanted to get:
{'Pepperoni': 'Pizza', 'Cheese' : 'Pizza'}
 
there is only one value, which is a 2-element list
you happen to unpack that 2-element list into k, v
what you might have meant is for k,v in m.items() but then you also have to loop over v because v will not be hashable
Do you know how nested comprehensions work?
 
Not exactly, no.
 
>>> {kind: meal for meal, kinds in m.items() for kind in kinds}
{'Cheese': 'Pizza', 'Pepperoni': 'Pizza'}
the equivalent for loop would look like
for meal,kinds in m.items():
    for kind in kinds:
        ...
 
Oh I see now
That makes sense, I tried editing it after your comment.
But was doing k, v for v in m.items()
Thank you, I'll go read up on the nested comprehensions.
 
They're mostly like regular ones, the only thing to keep in mind is that you have to keep the fors in the same order.
 
8:05 PM
Okay!
 
I suggest first writing it out in a proper nested loop, and then if you understand that, converting to a nested comprehension.
and use them sparingly, because too complicated comprehensions start to be unreadable :)
 
8:18 PM
Im going to present an early version of my software to people with no programming background, can you tell me from your experience what impressed non technical folks ?
 
It's hard to say anything general I think. As a rule of thumb people like pretty pictures.
for anyone to be able to answer you'd probably have to tell what your program does and how the non-technical people are related to the program
 
9:19 PM
probably more of a math question, but how would I go about reversing x *y % z in python? I feel the 3.8 pow() update with modinv would help but not sure
ah looks like just interchanging the result with x works
 
9:36 PM
actually not really, if anyone is interested it was multiplicative cipher :P
http://pi.math.cornell.edu/~mec/Summer2008/lundell/lecture3.html
 

« first day (3514 days earlier)      last day (1427 days later) »