« first day (1848 days earlier)      last day (3293 days later) » 

06:15
I need a Python person. @Mego, are you still around?
Anonymous
@AlexA. You know it
Anonymous
> implying that I sleep
Say I have a dict where each key and value is a string. But I have a desired mapping from key to value type. What's the most efficient way to do that?
value type?
Anonymous
06:17
Can you elaborate?
Say I have something like {"id": "1", "date": "2016-01-04"} and I want {"id": 1, "date": <datetime object>}
For each key in the dict, there's a specific type I want the value to have.
Anonymous
Probably iterate over the keys, and select the construction method based on the key
Anonymous
Lemme type up the awful example of how I would probably do it
So something like for key in dict: if key == "id": dict[key] = int(dict[key]), etc?
84
A: Fastest way to convert a dict's keys & values from `unicode` to `str`?

RichieHindleDATA = { u'spam': u'eggs', u'foo': frozenset([u'Gah!']), u'bar': { u'baz': 97 }, u'list': [u'list', (True, u'Maybe'), set([u'and', u'a', u'set', 1])]} def convert(data): if isinstance(data, basestring): return str(data) elif isinstance(data, collections.Mapping): ...

wait what
can't you just parse as json?
06:21
It's not that the entire dict is a string
Both the keys and the values are strings
But I want the values to be of different types, where the specific type depends on the key
can't you have
MAPPING = {
    'id': int
    'date': time.strptime
}
then do MAPPING[key](value)?
Yeah, I thought about that. Wasn't sure whether that'd be more efficient.
Anonymous
It's probably the most Pythonic way
Anonymous
06:26
Other than "don't get yourself in this situation"
I'm parsing XML, but the raw XML has everything as strings.
Looks like the mapping thing is what you suggest as well
Anonymous
Eww gross
Cool beans
Anonymous
Yeah the mapping is how I'd do it
Anonymous
You could also make it a defaultdict with str as the default value
Anonymous
06:27
@somebody That doesn't work; iter(data) only iterates over keys
Anonymous
You'd need data.items() or data.iteritems()
^ Isn't one of those deprecated or removed in Python 3?
Anonymous
data.items() in 3 is data.iteritems() in 2
Oh, okay
Anonymous
In 3, basically everything returns an iterator object rather than a list
Anonymous
06:29
Which means a lot of itertools stuff got promoted to builtins - 3's map is 2's itertools.imap
Would it be more Pythonic and/or efficient to use get with a default of lambda x: x when I'm applying the mapping?
(I could be remembering Python's get incorrectly; I'm used to Julia's.)
Anonymous
That's how get works, and sort of
Anonymous
The defaultdict is probably what most Pythonista would say :P
Anonymous
With defaultdict (the default arg is ugly as sin though)
Anonymous
The default_factory argument expects a function, and since the values are functions, you have to provide a function that, when called, returns the identity function
06:40
Gross
/me needs help
Anonymous
Yeah I dunno what could be done to make it cleaner
Your original method seems much cleaner
i have no idea how to make codegolf.stackexchange.com/questions/tagged/tips into a github pages + jekyll repo
Anonymous
Step 1: don't
06:42
^
why not?
Anonymous
Why?
idk
it's a lot easier see tips
not half a page for each suggestion, instead it's one line
not 4 pages of python tips, 2 screens on a laptop/desktop
I don't see how GitHub Pages and Jekyll would solve that
the markdown should be the easy part
just have a table: tip | before | after
06:50
since someone was posing about radiation-hardened quines, it is impossible to write one in a language like C right?
Anonymous
Yep
Anonymous
Erase any character in main, gg
@Mego I'll believe it if you show me a proof :P
can someone give me a one-liner about how the one in ruby works
(i don't know how ruby works at all)
link?
Anonymous
In C, C++, Java, or any similar language that requires a certain string to be in the program to be valid, it's impossible to write a true radiation-hardened quine
Anonymous
(C# and VB are similarly impossible)
Anonymous
Simple remove a letter from main/Main and you're hosed
This is a strange smiley face...
I don't understand...
Anonymous
It's the radiation symbol
Anonymous
07:00
Anonymous
See: Beta Decay's old avatar
..... Now I just feel dumb
Anonymous
It's ok, we all feel that way sometimes
I don't usually though :-)
@Justin Somehow, I think many in this room would think the same of themselves. :P
It's certainly a rarity for me.
07:10
Even if I ask a dumb question, I don't feel dumb :)
07:22
I feel dumb 24/7. #dumblife
Anonymous
Aww but we <3 you
07:48
Has anyone else known about this site? I love it lobste.rs
My Pyth install is still borked ;-;
08:19
> My borked is still Pyth install
@Quill Still borked, my Pyth install is
Yoda, I am
yoda u is
09:11
0
Q: A program that prints pi

Alex82You have to create a program that prints pi, with 100 decimal places. This is code golf, so the smallest program wins!

09:28
0
Q: Find median of grouped continuous data

ghosts_in_the_codeYou will be given grouped continuous data, such as the following: Class Frequency 0-10 3 10-20 6 20-30 4 30-40 7 Your job is to find the median using the following formula: l+(N/2-cf)*(h/f) where l = lower limit of median class N = sum of all frequencies cf = cumulative frequency ...

10:24
@somebody what's that github organisation?
to collect the tips from all the 'tips for <language>' threads and displaying them in an easy-to-read format
nobody likes them though, so probably gonna delete it
@Calvin'sHobbies how does env appear? the js sends and empty object to execute()
wait, nvm
10:47
⁽⁽(੭ꐦ •̀Д•́ )੭*⁾⁾ ᑦᵒᔿᵉ ᵒᐢᵎᵎ
Pyth still is bork
Glad there's a web interpreter
11:35
when a challenge requires an integer argument, are you required to use a numeric type if you have one, or can you accept it in string form?
@somebody ah well, I agree that it can be a bit annoying to read all the tips for a language, but some of them aren't as simple as "long form -> short form", and I don't think there's generally much point in duplicating all the content, especially since it's bound to get outdated.
11:54
sigh, I had just written an answer for a question when it gets closed
0
Q: Weight balancing problem

AdamantiumHave you ever wondered, when doing shopping, how to pack your products into 2 bags you're carrying so that a total weight would be distributed among them as evenly as possible? Your task is to write a function, that takes a list of positive numbers (lets say integers for simplicity) as an input....

12:13
@Mego finished porting Shtriped
@Calvin'sHobbies this isn't wotking for me
not printing last row
@Mego whoops, maybe not
@Mego now it's exactly the same as the JS
idk if i should port to anything other than python 2/pypy
@Dennis maybe you could add Shtriped to TIO?
12:52
THE KERNEL HAS EVOLVED
RUN FOR YOUR LIVES
13:31
0
Q: How to fix linker error LNK2019: unresolved external symbol and error LNK2001: unresolved external symbol

Samitha PalihawadanaI am new to visual studio. I am going to study libxml2 library. So my first example is parsing a xml file. I follow libxml2 official tutorial. http://xmlsoft.org/tutorial/ I set the additional include directory path suitably. But there are build errors still remaining. my cpp file is in http://xm...

13:41
> help me.
@MartinBüttner ?
from that off-topic question
move to SO?
I'm not going to migrate it. they can repost it there if they want
oh
also, help me. = best question ever
13:58
@Dennis is the bubblegum source available online?
grc
grc
14:14
ಠ_ಠ
14:29
( ͡°╭͜ʖ╮͡° )
Lot of stuff getting put on hold today...
@VoteToClose ?
@VoteToClose Just created a pull request, could you check it?
14:45
@orlp wow french beard
@Doorknob And sure enough he got it down to 26 just now :P
haha, 8, not bad
@LegionMammal978 Accepted.
It's interesting how a packet can almost instantaneously cross 5000 miles under the Atlantic Ocean and back just to ping a server
@somebody Sure. The JavaScript or Python version?
15:01
There's a JS version? I thought the only implementation was the reference Python one on esolangs
@LegionMammal978 Internet is awesome. c:
guys
I have a problem
I have a histogram of occurences
e.g. A = 25, B = 3, C = 0, D = 1, E = 10
blablabla
15:09
Okay...
I want to turn this into cumulative probabilities
this is not so hard
you sum
(25 + 3 + 0 + 1 + 10) = 39
Then take the ratios
Indeed, so A = 25/39, B = 28/39, C = 28/39, D = 29/39, E = 39/39
but now comes the hard part
I want the ratios as 15-bit fixed point
where the cumulative probability doesn't go from 0 to 1 as a real number, but from 0 to 0x7fff as an integer
and the second requirement is that if a probability has non-zero chance, it must not get round down to 0
@LegionMammal978 I should've said from 0 up to and including 0x7fff
the third requirement is that the cumulative fixed point probability represents the histogram as accurately as possible
15:12
*0x7fff, then round up?
and the last requirement is that the cumulative probability must be exactly 0 to 0x7fff
@LegionMammal978 then you will go over 0x7fff
because rounding up makes the total larger
No
The maximum is 1
1 * 0x7fff is 0x7fff
Rounded up is still 0x7fff
oh, then you don't fulfill the second requirement
since 0.9999 * 0x7fff would round up to 0x7fff
and the last 0.0001 just got rounded to zero
15:14
The requirement only talks about a non-zero chance
yes
if an event has a cumulative probability of 0.9999
then there is an event after it with a non-zero probability less or equal than 0.0001
*0x7ffd+1
0x0000 represents 0
0x7ffff represents 1
... let me illustrate by example
@LegionMammal978 try your approach on probabilities A = 99999/100000 and B = 1/100000
f(A) is 0x7fffe and f(B) is 0x0001
@LegionMammal978 how did you get 0x7fffe?
you rounded up, didn't you?
15:17
I'm rounding normally this time
Except that 0x0000 and 0x7fff are reserved for 0 and 1
@LegionMammal978 then please exactly explain your algorithm
because right now it's just handwaving
2 mins ago, by LegionMammal978
*0x7ffd+1
2 mins ago, by LegionMammal978
0x0000 represents 0
with what rounding?
2 mins ago, by LegionMammal978
0x7ffff represents 1
Rounding normally otherwise
'normal' is not a rounding mode
what rounding?
nearest integer?
15:19
yes
banker's rounding?
ok, here is where your scheme goes wrong
A = 99998/100000, B = 1/100000 and C = 1/100000
that becomes 0x7ffe, 0x1 and 0x1
total = 0x8000 > 1
starting to see the issue?
Kinda
Is there a definite range to the amount of data
Well, for the problem to be possible the number of symbols must be < 0x7fff
but other than that a division is always possible
the problem is to make the division as representative of the histogram as possible
15:22
Can you just use the numerator and then store the denominator separately?
Nope, the cumulative probability must exactly become a 15-bit integer.
What is this for?
arithmetic coding
Very tight requirements
well, a solution is always simple
assign 1 to every symbol with nonzero probability except the last, which gets whatever is left
the problem is to make the solution represent the histogram as accurately as possible
15:26
It's tricky with just 15 bits
But wait
You have 15 bits per symbol!
@LegionMammal978 nope
the cumulative probability goes from 0 to 0x7fff
7 mins ago, by orlp
that becomes 0x7ffe, 0x1 and 0x1
e.g. to give an example if it were to go from 0 to 10
15 * 3 = 45 bits total
nope
you don't understand
the output has to be
such that the sum of the probabilities is exactly 0x7fff
15:28
I know
Just saying that there doesn't have to be a 1-to-1 mapping between words and symbols
@LegionMammal978 what do you mean with a word?
15-bit block
For example, in my old attempted solution, I had 0x7ffe00010001 for A,B,C combined
no
you had 0x7ffe + 0x1 + 0x1 = 0x8000 combined
No, I'm talking about the amount of bits we have
For storage
why is that relevant?
I never mentioned storage requirements?
15:33
True, but better storage utilization means better accuracy
?
what?
Let me think
Wait, do you know if there is a solution?
Of course
There always is
Assign 0x1 to every nonzero symbol except the last, which gets whatever is left
But an accurate one, that is
it's a bad solution (not very representative of the histogram), but it is one
@LegionMammal978 define 'accurate'
15:37
One that can represent differences between values
That's too vague
I really shouldn't need to explain why that's too vague
Your solution makes it seem as if every symbol (except the last) has the same value
Feb 12 at 20:06, by mınxomaτ
When you sign up for the wrong exam timeslot and have to study a whole semester worth of stuff in like 50h...
Had this exam today...
15:40
My solution just shows that there is always a valid solution, then you can start to shuffle probabilities around to better match the histogram
I see
Another possible one is to just multiply by 0x7fff, rounding towards 50%
Leave the last symbol out
@mınxomaτ Feel good about it?
as it is just 1- the sum of the others
Actually, there's an idea
@VoteToClose I have no idea....
Well, good luck. :D
15:43
Take a set of possible formats, and choose one based off of the last symbol's value
10 weeks minimum to grade. Plenty of time to forget :D
@LegionMammal978 formats?
Come up with several solutions
and choose the one that best fits the data
And there's my solution
Again, too vague man.
Be specific
So, say you have your solution, right?
15:44
The terrible one?
Sure.
Let's assume it best fits the data somehow
Now set the first n-1 symbols according to that (so set them to 1)
Say this solution is solution #0x4567
So set the last symbol to that
Because we can calculate its value
How can I set the 'last' symbol to a solution?
where does the 0x4567 come from?
It's your 0x4567'th solution to this problem
Out of your set of solutions
For example,
that impossible
if you have set the first n-1 symbols
the last symbol is ALWAYS fixed
since the sum must be 0x7fff
take A=1/1000, B=1/1000, C=1/1000, and D=9997/1000
And your terrible solution works best somehow
Then you have 0x1, 0x1, 0x1, and 0x4567
15:49
no
that doesn't sum to 0x7fff
We can calculate D from A, B, and C
so it's not a valid solution
But it does
0x1 + 0x1 + 0x1 + 0x4567 != 0x7fff
When decoding, we choose D so that it does sum to 0x7fff
The 0x4567 is metadata
15:49
.....
there is no 'decoding'
there is no 'metadata'
Then when reading the representation
what 'representation'?
what the hell are you going on about
you simply have to output the cumulative probability using an array of fixed-point 15-bit integers
The representation of the data
there is no 'representation'
you are severely confused
Then what have we been doing to the histogram, if not representing it?
15:52
1 min ago, by orlp
you simply have to output the cumulative probability using an array of fixed-point 15-bit integers
we've not been doing anything to the histogram
it's not a representation
at best it's a model
You've been converting it to an array
I'm proposing a different conversion process
I'm not interested in that
Which requirement does it break?
My proposed solution works at least as well as yours
You still haven't given a solution that is sufficiently precise to verify
It's more of a meta-solution
Its effectiveness depends on the 0x8000 regular solutions you choose
If you want a regular one, here:
Set n-1 symbols to 0x1
Set the last one to 0x2345, as it doesn't really matter because we can compute its value from the others anyway
(Of course, that's just being wasteful)

« first day (1848 days earlier)      last day (3293 days later) »