|
Let's say that a = 5 and b = 5 and c = 5 Is this a safe condition to check: Python code:
Python code:
|
# ? Jul 2, 2014 15:18 |
|
|
# ? May 9, 2024 07:30 |
|
the posted:Let's say that a = 5 and b = 5 and c = 5 Yes.
|
# ? Jul 2, 2014 15:29 |
|
Follow up question: Let's say I have three lists, A contains 100 entries, B contains 1000 entries, and C contains 1000000 entries. I want to compare them and find the matching entries. My first thought was just to do a nested loop to check: Python code:
Python code:
|
# ? Jul 2, 2014 15:33 |
|
the posted:Follow up question: Let's say I have three lists, A contains 100 entries, B contains 1000 entries, and C contains 1000000 entries. code:
|
# ? Jul 2, 2014 15:40 |
|
good jovi posted:
Thanks, but the problem is that the lists won't have exact entries. I'm linking them by a unique ID that's included in all the lists, but they're lists of different things.
|
# ? Jul 2, 2014 16:28 |
|
the posted:Thanks, but the problem is that the lists won't have exact entries. I'm linking them by a unique ID that's included in all the lists, but they're lists of different things. If items in the lists have a unique ID, why aren't you storing them as a dictionary where the ID is the key and the other items in the list are the value? That would make it really easy to do set operations with just the IDs.
|
# ? Jul 2, 2014 16:44 |
|
the posted:Thanks, but the problem is that the lists won't have exact entries. I'm linking them by a unique ID that's included in all the lists, but they're lists of different things. That sounds really awkward, and you should think about how to store these items more efficiently. Think about what "equality" really means for these objects. Consider encapsulating them in something (a class) that defines __eq__ and __hash__ in a logical way such that objects considered equal in your problem domain are actually treated as such. Don't let Python's default comparison behavior limit you, that's just a default.
|
# ? Jul 2, 2014 17:16 |
|
BeefofAges posted:If items in the lists have a unique ID, why aren't you storing them as a dictionary where the ID is the key and the other items in the list are the value? That would make it really easy to do set operations with just the IDs. I'm using Beatbox to query a Salesforce database for different entries like Contacts and Accounts. So a Contact query would look something like this: ['Contact', '00001123443AXQ', 'John Smith'] And an Account query might look something like this: ['Account', '00001123443AXQ', 'City of Austin,' 'TX', '20441'] And I'm running a comparison check for that account ID and storing the information I need when I find it. I'll admit I haven't worked with dictionaries enough to know that it's possible to store everything like that in one.
|
# ? Jul 2, 2014 18:32 |
|
the posted:I'm using Beatbox to query a Salesforce database for different entries like Contacts and Accounts. With a dictionary, you can have a list as a value. So the key for both dictionaries would be '00001123443AXQ' and the value in one dictionary would be ['Contact', 'John Smith'] and the other dictionary it would be ['Account', 'City of Austin', 'TX', '20441'].
|
# ? Jul 2, 2014 18:39 |
|
QuarkJets posted:With a dictionary, you can have a list as a value. So the key for both dictionaries would be '00001123443AXQ' and the value in one dictionary would be ['Contact', 'John Smith'] and the other dictionary it would be ['Account', 'City of Austin', 'TX', '20441']. You could even have a dict as a value if it was useful to you. {'00001123443AXQ': {'city': 'City of Austin', 'state': 'TX', 'zip': '20441'}} If you were feeling crazy you could create a Contact and Account class and attach some behavior to them instead of using a dict.
|
# ? Jul 2, 2014 18:42 |
|
the posted:I'm using Beatbox to query a Salesforce database for different entries like Contacts and Accounts. If query is a list of lists, and the account number is always index 1 of each sublist: Python code:
e: I would have suggested a class, but I wanted to elaborate on dictionaries for a little bit because dictionaries are cool. So what you should do is make dictionaries of class instances that hold your data instead of dictionaries of lists that hold your data QuarkJets fucked around with this message at 18:48 on Jul 2, 2014 |
# ? Jul 2, 2014 18:46 |
|
the posted:I'm using Beatbox to query a Salesforce database for different entries like Contacts and Accounts. I think what they are trying to suggest is that you work with dictionaries that look like this: code:
code:
code:
|
# ? Jul 2, 2014 18:49 |
|
Thanks, guys. Looks like this is working well. A good way to simplify the process and information handling. Much thanks!
|
# ? Jul 2, 2014 19:10 |
|
Does anyone have any idea why Flask would be causing connection refusals (i.e. socket error 10061) on any given port using the basic "hello world" script on the website:Python code:
Python code:
I also installed Flask using pip install Flask if that matters. It installed everything Flask depends on, such as Werkzeug, no problem.
|
# ? Jul 2, 2014 23:28 |
|
I've been wondering about that, actually. I commonly find myself in a situation where I have data such as a bunch of subsets, complicated objects, and huge flat dictionaries. Is there a specific pattern to creating those kindsa data structures, or is it more or less what's easiest?
|
# ? Jul 3, 2014 00:49 |
|
the posted:Thanks, guys. Looks like this is working well. A good way to simplify the process and information handling. Much thanks! I know you've found a solution you're happy with, but I briefly glanced at beatbox and it looks like it lets you directly send SQL queries, in which case it might be faster to do a join in your query and let the server do the heavy lifting instead of trying to merge your datasets locally.
|
# ? Jul 3, 2014 02:28 |
|
BeefofAges posted:I know you've found a solution you're happy with, but I briefly glanced at beatbox and it looks like it lets you directly send SQL queries, in which case it might be faster to do a join in your query and let the server do the heavy lifting instead of trying to merge your datasets locally. ...Go on... (I don't know what you mean by join in your query)
|
# ? Jul 3, 2014 03:33 |
|
the posted:...Go on... You are probably firing two or more of those: One may be: SELECT id_butt, whatever1 FROM butts And the other may be: SELECT id_fart, id_butt, whatever2 FROM farts The result is that you have now two separated sets of data that are logically related. Modern databases are handy in that relational databases are all the rage for quite some time now. Instead of having two sets of separated but related data, you can have only one set of related data, saving you the hassle of JOINing them yourself. The database excels in that already. Something like this: SELECT b.id_butt, b.whatever1, f.id_fart, f.whatever2 FROM butts b, farts f WHERE f.id_butt = b.id_butt; My SQL is quite rusty, so that may not be quite right (sqlalchemy ), so I'll just leave you a link to the CoC SQL megathread. Sorry for not being more helpful.
|
# ? Jul 3, 2014 03:57 |
|
QuarkJets posted:e: I would have suggested a class, but I wanted to elaborate on dictionaries for a little bit because dictionaries are cool. So what you should do is make dictionaries of class instances that hold your data instead of dictionaries of lists that hold your data Or namedtuples for the values of the dictionary.
|
# ? Jul 3, 2014 04:23 |
|
HardDisk posted:butts Got it, I'll look into that tomorrow, thanks!
|
# ? Jul 3, 2014 04:30 |
|
Optimus Prime Ribs posted:My Flask problem... Been fighting with this for hours and talked with some goons on IRC whom couldn't figure it out either, so I'm quite prepared to say "gently caress Flask" and use something else (Flask is the only thing that won't work on my server). What is a good alternative to Flask? Or would that question be better for the web design/development thread?
|
# ? Jul 3, 2014 05:36 |
|
Optimus Prime Ribs posted:Been fighting with this for hours and talked with some goons on IRC whom couldn't figure it out either, so I'm quite prepared to say "gently caress Flask" and use something else (Flask is the only thing that won't work on my server). I know nothing of your requirements, but you should just use Django.
|
# ? Jul 3, 2014 05:42 |
|
If you need the light weight of flask, try bottle.
|
# ? Jul 3, 2014 05:55 |
|
The March Hare posted:I know nothing of your requirements, but you should just use Django. Isn't Django intended for large scale web applications? Anything I'll be developing won't be super complex, and Django looks like a hell of a beast of a web framework that would probably be overkill. First thing that I'm doing to be making will just be a basic website to show my portfolio and contact information, and after that probably just a simple game that will mostly run off of HTML5/JavaScript. Hed posted:If you need the light weight of flask, try bottle. I do like lightweight frameworks, and bottle looks pretty interesting. I've got it installed and working on my server, so I'll play around with it and see what I think. Thanks. e: Flask is working now, and I didn't change anything. Optimus Prime Ribs fucked around with this message at 06:28 on Jul 3, 2014 |
# ? Jul 3, 2014 06:19 |
|
Is there an easy way to get OpenCV into a portable anaconda installation? I've tried to do this myself (in CentOS), but somehow I keep getting a cv2 module that's simply hosed. I try to do an image resize and it gives me an array full of 0s with a handful of non-zero pixels, and if I try to create a bilateral filter then it just instantly seg faults.
|
# ? Jul 3, 2014 08:53 |
|
BigRedDot posted:This is a really good question, but also fairly technical one, your best bet is the mailing list anaconda@continuum.io or the GH issue tracker https://github.com/ContinuumIO/anaconda-issues
|
# ? Jul 3, 2014 17:40 |
|
Dominoes posted:Thanks - submitted issues to both. My main issue with this is that I switched to Anaconda to make package management easier, but the workarounds for PyQt5 nullify this advantage. While I got the workarounds done on Windows by installing binaries, I still haven't figured it out on Ubuntu - the PyQt5 package uses the system Python3, and I'm no good at building things from source. You may want to try building from source a bit more; it's often extremely easy, just more time-consuming.
|
# ? Jul 3, 2014 19:03 |
|
A friend was working on a rot13 script to learn Python, so I gave it a shot myself to compare. I wanted to get it down to a lower line count, so I moved the results of the if-statements onto the same line, is that acceptable?code:
|
# ? Jul 3, 2014 20:51 |
|
Literally Elvis posted:A friend was working on a rot13 script to learn Python, so I gave it a shot myself to compare. I wanted to get it down to a lower line count, so I moved the results of the if-statements onto the same line, is that acceptable? No, not really. Line count is just a number. It's less readable to me, separating the condition from the action is difficult on a line that long. Also, you don't need to iterate over range(len(words)). You can just iterate over words itself.
|
# ? Jul 3, 2014 20:56 |
|
Literally Elvis posted:A friend was working on a rot13 script to learn Python, so I gave it a shot myself to compare. I wanted to get it down to a lower line count, so I moved the results of the if-statements onto the same line, is that acceptable? That approach is not terribly readable (you could consider lining the "result" statements up vertically), but the real bad news is that technically this doesn't reduce the "line count". You just have two SLOCs (an "if" and a "result +=") on a single line in your text editor. I believe that in theory you could actually put the whole program (as is) on one line.
|
# ? Jul 3, 2014 20:57 |
|
Also if you really just want to code golf it, you can just cheat and leverage the batteries includedcode:
|
# ? Jul 3, 2014 20:59 |
|
good jovi posted:No, not really. Line count is just a number. It's less readable to me, separating the condition from the action is difficult on a line that long. qntm posted:That approach is not terribly readable (you could consider lining the "result" statements up vertically), but the real bad news is that technically this doesn't reduce the "line count". You just have two SLOCs (an "if" and a "result +=") on a single line in your text editor. I believe that in theory you could actually put the whole program (as is) on one line. thoroughly noted and script edited accordingly. code:
No Safe Word posted:Also if you really just want to code golf it, you can just cheat and leverage the batteries included I know that part of what makes Python great is the thoroughness of it's included functions, but I like implementing simple things like this because I think it's good practice. vv EDIT: are things like single line variable declarations okay? Literally Elvis fucked around with this message at 21:10 on Jul 3, 2014 |
# ? Jul 3, 2014 21:04 |
|
Literally Elvis posted:
Anything that decreases readability is not okay.
|
# ? Jul 3, 2014 21:26 |
|
EAT THE EGGS RICOLA posted:Anything that decreases readability is not okay. Dear God, I am maintaining code written by a mad scientist that is written like this. Please don't obfuscate your code.
|
# ? Jul 3, 2014 21:30 |
|
Literally Elvis posted:
You don't have to explicitly cast phrase to a list. You can iterate over a string, and it will just return each character. code:
code:
|
# ? Jul 3, 2014 21:42 |
|
Someone make a version of code golf where you win by writing the most easily readable code pls
|
# ? Jul 3, 2014 21:44 |
|
No Safe Word posted:Also if you really just want to code golf it, you can just cheat and leverage the batteries included I had no idea of this, I thought codecs had only serious stuff! Here's a dumb version just to show off some stdlib: Python code:
|
# ? Jul 3, 2014 22:36 |
|
Said friend here. This is how mine ended up. first time with python but i tried to cover all my bases. probably not the bestcode:
|
# ? Jul 3, 2014 22:38 |
|
theguyoncouch posted:Said friend here. This is how mine ended up. first time with python but i tried to cover all my bases. probably not the best Use actual words, don't put compound statements on one line, get rid of most of the comments (your code should self-document for something this simple), put the declarations on separate lines, and join your string like this: code:
edit: HardDisk posted:Don't use tabs. Use spaces, preferably 4. aag, that too EAT THE EGGS RICOLA fucked around with this message at 23:27 on Jul 3, 2014 |
# ? Jul 3, 2014 23:15 |
|
|
# ? May 9, 2024 07:30 |
|
theguyoncouch posted:Said friend here. This is how mine ended up. first time with python but i tried to cover all my bases. probably not the best Don't use tabs. Use spaces, preferably 4.
|
# ? Jul 3, 2014 23:24 |