|
hooah posted:Alright, forgoing the hotkey thing for a bit, why doesn't this work? Because it IS returning list. Also the better way to do this (though duck typing is bad in general) is to use "if isinstance(x, list)" Edit: vvv I completely missed that, that's absolutely right. Jewel fucked around with this message at 01:42 on Oct 19, 2014 |
# ? Oct 19, 2014 01:32 |
|
|
# ? May 9, 2024 12:55 |
|
You had the right idea without quotes around 'list' in the condition -- list, a reference to the built-in type, is what type should return when given [1, 2] -- not 'list', a string bearing its name. There's one problem: you used "list" as the name of your function's argument. In the scope of your function, list now refers to the value [1, 2, [1, 2]] and not the built-in type it refers to everywhere else. So you're testing if type([1, 2]) returns [1, 2, [1, 2]], which it of course does not. So that's why you never overwrite the name of a built-in. Use pretty much anything else as the name of your function's argument, remove those quotes and it will work fine. An IDE like PyCharm will warn you when you do something like that. (Also what the above said about using isinstance, and, even better, testing against I think collections.Iterable to catch tuples, sets and the like.) KICK BAMA KICK fucked around with this message at 01:40 on Oct 19, 2014 |
# ? Oct 19, 2014 01:37 |
|
gently caress, I really should know better than to shadow built-in stuff after over a year of C++. Also, didn't know about isinstance yet, thanks. Back to Think Python!
|
# ? Oct 19, 2014 01:46 |
|
KICK BAMA KICK posted:(Also what the above said about using isinstance, and, even better, testing against I think collections.Iterable to catch tuples, sets and the like.) Just a note: It's collections.abc.Iterable now. https://docs.python.org/3/library/collections.abc.html
|
# ? Oct 19, 2014 02:26 |
|
KICK BAMA KICK posted:(Also what the above said about using isinstance, and, even better, testing against I think collections.Iterable to catch tuples, sets and the like.) >>> isinstance("a",collections.Iterable) True That test also returns true for sequences, like strings. On the other hand hasattr(x, "__iter__"), will pick up any iterable, but not strings.
|
# ? Oct 19, 2014 19:37 |
|
tef posted:>>> isinstance("a",collections.Iterable) I assume in the real world the correct way to solve the original problem would involve something clever with itertools.chain.
|
# ? Oct 19, 2014 20:01 |
|
KICK BAMA KICK posted:Fair point for Python 2 but strings do have an __iter__ method in Python 3.
|
# ? Oct 19, 2014 20:31 |
|
I assume nested_sum is for a class, but for future reference, you shouldn't ever have weird data structures like that.
|
# ? Oct 19, 2014 22:50 |
|
Has anyone here legit used bitwise operators in Python in their career yet? (Other than job interview questions -- I got grilled on it as a first question and was a bit puzzled as to why)
|
# ? Oct 19, 2014 23:18 |
|
ShadowHawk posted:Has anyone here legit used bitwise operators in Python in their career yet? (Other than job interview questions -- I got grilled on it as a first question and was a bit puzzled as to why) Sure, I've used them to compute hamming distances in a search application prototype, for doing time-constant string compares (though normally you should be using hmac.compare_digest() or a similar library function), and I'm using them as I'm working my way through the Matasano crypto challenges. They just show up in programming from time to time irrespective of language. suffix fucked around with this message at 23:37 on Oct 19, 2014 |
# ? Oct 19, 2014 23:33 |
|
I used them when computing numpy arrays as masks for the 2011 ants AI challenge.
|
# ? Oct 19, 2014 23:47 |
|
I haven't done a single bitwise operation since the last embedded systems project I worked on in college.
|
# ? Oct 20, 2014 00:20 |
|
I regularly use unary not (~) for negating boolean Pandas data structures (both Series and DataFrames).
|
# ? Oct 20, 2014 01:37 |
|
I guess a better question, is has anyone used bitwise operations where they were legitimately better choice over alternative options? I'll come across them in someone else's code every once in awhile and I've yet to see a case where they weren't just trying to be clever. I'm sure there are good uses, but from my experience the ratio between times bitwise operations are used and times when bitwise operations should be used is not that great.
|
# ? Oct 20, 2014 01:39 |
|
I use them to extract color values from RGBA snippets. Or, in more abstract terms, extract records from bit packed formats. I use them when doing bit-level reading for things like Huffman Coding. I use them to compute powers of two or upper limits of a specific size. Doing 1 << 8 instead of 2**8 is arguably a matter of taste, though I prefer the former. Really, bit level twiddling is very useful, and I use the bit twiddling operators whenever I need to bit twiddle.
|
# ? Oct 20, 2014 01:49 |
|
ShadowHawk posted:Has anyone here legit used bitwise operators in Python in their career yet? (Other than job interview questions -- I got grilled on it as a first question and was a bit puzzled as to why) They're overloaded in sqlalchemy's ORM to do OR/AND, but otherwise nope.
|
# ? Oct 20, 2014 17:00 |
|
How can I make a dictionary of dictionaries like the following with the keys coming from two other files: file one contents: key1 key2 key3 file two contents: foo bar etc. {somekey {key1: undef, foo: undef, bar: undef, etc.} {key2: undef, foo: undef, bar: undef, etc.} {key3: undef, foo: undef, bar: undef, etc.} }
|
# ? Oct 20, 2014 17:01 |
|
I'm unclear on what you actually want, but maybe this?Python code:
Python code:
Space Kablooey fucked around with this message at 18:43 on Oct 20, 2014 |
# ? Oct 20, 2014 18:40 |
|
Can somebody repost the Python random seeded number fizz buzz?
|
# ? Oct 21, 2014 00:55 |
|
Sitting Bull posted:Can somebody repost the Python random seeded number fizz buzz? Python code:
|
# ? Oct 21, 2014 06:27 |
|
I'm trying to install Pandas using pip, but I keep on getting the following error:code:
E: also, the version of Python that came bundled with osx is located under system/library/frameworks/Python.framework, but the 2.x and 3.x versions I've manually installed are located at library/frameworks/Python.framework. Is there an easy way to get all versions of Python in the same location without breaking anything? regularizer fucked around with this message at 09:09 on Oct 21, 2014 |
# ? Oct 21, 2014 08:22 |
|
Pip tends not to work for packages that use non-Python code. I don't know the details of OSX, but on Linux, you'd use a package, and on Windows, you'd use a binary. Anaconda is another option.
|
# ? Oct 21, 2014 11:33 |
|
Use Homebrew Also unless you're using Pandas for a specific project and are using virtualenv it might make sense just to use the Anaconda distribution as it's entirely packaged and you don't have to deal with the insanely long compilation process.
|
# ? Oct 21, 2014 11:34 |
|
ShadowHawk posted:
That is pretty brilliant in a horrible horrible way... I guess if you first wrote a program to iterate through the first 15 values from each seed until you found a match for FizzBuzz... but who even thinks of these things?
|
# ? Oct 21, 2014 12:12 |
|
Dominoes posted:Pip tends not to work for packages that use non-Python code. I don't know the details of OSX, but on Linux, you'd use a package, and on Windows, you'd use a binary. Anaconda is another option. A big part of the reason I switched my dev environment to Linux was because libraries that require compiling work with pip.
|
# ? Oct 21, 2014 17:05 |
|
Hi guys. Hoping to get a bit of guidance, because I am totally stuck. I'm attempting to use a library (module?) to create a data visualization. This library requires, among other things, that numpy and scipy be installed. When I attempt to use the module via command line, it gives me the following error: code:
I am pretty (very) new to using python and I'm just not even sure where to look to figure out what is causing this problem. If this isn't the right place to ask or if I should be directed to some reference materials first, please let me know :-)
|
# ? Oct 21, 2014 22:42 |
|
AgentSythe posted:Hi guys. Hoping to get a bit of guidance, because I am totally stuck. On a phone so this will be short. Don't compile things it just results in headaches. On Windows, I strongly recommend miniconda. After the install just type "conda install scikits-learn" and all dependencies will be installed. The other option is installing all programs from the website you linked. That was my previous method before miniconda.
|
# ? Oct 21, 2014 23:11 |
|
Personally, I like just plain old Anaconda. In either case, installing individuals Python packages in Windows causes headaches, use something like Anaconda or miniconda
|
# ? Oct 21, 2014 23:29 |
|
Thanks for the quick response. I had no idea that was even a possibility or something I should be looking at. I will tear down what I attempted today and use that method.
|
# ? Oct 22, 2014 00:26 |
|
And like accipter said, Chris Gohlke's lfd.uci site is great for Windows binaries if you're not using Anaconda. It's kept up-to-date, and you just run the installers and the packages work. However, for the more complex packages, you may need to download a separate installer for each dependency.
Dominoes fucked around with this message at 01:50 on Oct 22, 2014 |
# ? Oct 22, 2014 01:48 |
|
ShadowHawk posted:
This is totally cheating unless you find a seed that actually works up to 100.
|
# ? Oct 22, 2014 01:56 |
|
EAT THE EGGS RICOLA posted:This is totally cheating unless you find a seed that actually works up to 100. It's cheating no matter what, but it does go up to 100 (see the `i+1`). It goes up to any n, actually, since you're reseeding every 15 steps. I suppose it would be possible to find a seed that gave the entire 100-item sequence, but finding this one took long enough.
|
# ? Oct 22, 2014 02:39 |
|
good jovi posted:It's cheating no matter what, but it does go up to 100 (see the `i+1`). It goes up to any n, actually, since you're reseeding every 15 steps. I suppose it would be possible to find a seed that gave the entire 100-item sequence, but finding this one took long enough. I meant that it's cheating if your seed doesn't give the entire sequence.
|
# ? Oct 22, 2014 14:34 |
|
EAT THE EGGS RICOLA posted:This is totally cheating unless you find a seed that actually works up to 100. To be clear, finding a brute force solution that goes up to 100 is 2^170 times harder.
|
# ? Oct 22, 2014 14:37 |
|
ShadowHawk posted:To be clear, finding a brute force solution that goes up to 100 is 2^170 times harder. Yes, but if you're going to do something ridiculous you might as well do it properly.
|
# ? Oct 22, 2014 14:41 |
|
EAT THE EGGS RICOLA posted:I meant that it's cheating if your seed doesn't give the entire sequence. aw jeez man, I had enough to worry about. I guess my first question is whether or not I can expect to find an answer before the heat death of the universe.
|
# ? Oct 22, 2014 15:22 |
|
Pandas question. I have the following code and I am having trouble understanding why the warning is being thrown:Python code:
|
# ? Oct 23, 2014 18:56 |
|
Jose Cuervo posted:Pandas question. I have the following code and I am having trouble understanding why the warning is being thrown: By doing your selection in two parts you've wound up with a copy of your original data and assigned to that. If you look at your original dataframe, you'll see it is unchanged. If instead you do code:
code:
|
# ? Oct 23, 2014 20:59 |
|
Every time I start PyCharm, I get a notification from Soluto that Python has crashed. I also have noticed that I need to set the interpreter every time I start. Any ideas on either of these problems?
|
# ? Oct 24, 2014 01:07 |
|
|
# ? May 9, 2024 12:55 |
|
hooah posted:Every time I start PyCharm, I get a notification from Soluto that Python has crashed. I also have noticed that I need to set the interpreter every time I start. Any ideas on either of these problems? I had a bunch of problems with Pycharm crashing when I realized Linux was maxing out my VM drive storage with garbage logs in xsession-errors.
|
# ? Oct 24, 2014 01:34 |