every developer has their own git terror story. Yes, I mean "terror". See a horror story is when something terrible happens to you. A terror story is when you do something horrible to someone or something else (and usually yourself too)
Mine starts with those horrible words: "Well, the lead said to just commit it to the live server..."
@MalikBrahimi If your subclass keeps the two original fields and make the new one optional you should theoretically have Liskov substitutability, but since there's an ORM, I'm not placing any bets. (I'm not a Django person either.)
any ideas why Pyspark is throwing a tuple object cannot be called error for [StructField('id', StringTypes(), True)] ? Every example I've seen says that the parens are a must, and I just get a different error if I take them out.
@zounds Why Numpy? Numpy is great for fast array operations. But that code is doing dictionary lookups, so you should use plain Python. Does that code do what you want, or do you actually want the word associated with the minimum number, rather than the number?
Basically when I have a python file like:
python-code.py
and use:
import (python-code)
the interpreter gives me syntax error.
Any ideas on how to fix it? Are dashes illegal in python file names?
@IşıkKaplan All of that str -> int conversion stuff makes your code needlessly complicated and inefficient. Here's a simpler way:
num = 100
# Start with all doors closed
doors = [0] * num
for i in range(1, num + 1):
# Toggle each door whose index is divisible by i
for k, v in enumerate(doors, 1):
if k % i == 0:
doors[k - 1] = 1 - v
# Get the open doors
print([k for k, v in enumerate(doors, 1) if v])
`SparkException: Job aborted due to stage failure: Task 0 in stage 42.0 failed 1 times, most recent failure: Lost task 0.0 in stage 42.0 (TID 84, localhost, executor driver): java.text.ParseException: Unparseable number: "major_purchase" at java.text.NumberFormat.parse(NumberFormat.java:385)`
(major_purchase is a value of column purpose which Java is choking on)
interestingly enough it is row 19, so either the columns aren't ordered or something weird is going on
And len(s.split(','))>0 won't work, because if s doesn't contain a comma s.split(',') will return a list containing the original string, so len(s.split(',')) will always be at least 1, even if s is the empty string. Besides, splitting a string is relatively slow, compared to calling ,count, or doing an in test.
@MacSigler `Fraid not, but it's still early, so give it a few hours. Many of the room regulars do a quick skim of the transcript when they come online.
We will stop accepting contributions to Documentation on August 8
On behalf of everyone who worked on Documentation, I want to thank all 15,451 users who contributed. We particularly want to acknowledge the 294 people who tested the private beta and the 2,361 who pounded on the public beta in ...
I was thinking about the sort option... with timsort - the complexity won't be near worst case I imagine for that size list... although... where's a "partition" function when you want one :)
lst = [None, None, 90, 10, None, 34, None, 108]
idx = 0
for x in lst:
if x is not None:
lst[idx] = x
idx += 1
for k in range(idx, len(lst)):
lst[k] = None
print(lst) # [90, 10, 34, 108, None, None, None, None]
Closest I can get
This would be a very efficient solution in languages with real array types I guess.
I'm not sure why an answer posted after this got more upvotes than this did though they both say the same thing, or the fact that 5 people attempted to answer this, but this question has no upvotes. — cᴏʟᴅsᴘᴇᴇᴅ2 hours ago
Coldspeed seems a litty whiny about the question not getting upvotes…
hmm, not sure about that since it would first build up a list of Nones and then assign that to the slice. I’m also not sure how slice assignments actually work internally
In anyway, I opted for the constant space solution there, instead of having O(n) space for the None list
Also, my primary reason was to keep it “bare metal” as I was already going that route :P You can easily translate the solution into C or whatever
@poke Fair enough. The list multiplication is very fast. Slice assignments are a little faster than assigning in a Python loop, but slower than creating a new list with simple concatenation, and of course if we create a new list it's no longer an in-place solution.
In [14]: def f(iterable):
...: count = 0
...: for it in iterable:
...: if it is not None:
...: yield it
...: else:
...: count += 1
...: yield from repeat(None, count)
@khajvah It gets done at C speed, and it bypasses the usual progressive reallocation when you append stuff in a loop, since it knows ahead of time how much extra space it will need, so it can do a single reallocation.
@poke well - strangely - I have to think them up in my head first... then I generally like to try them out... bit difficult posting answers on SO saying "please refer to my brain's memory ingrams" :p
@piRSquared Yeah, ok. Though, popping inside a list is a little inefficient, since it has to move all the subsequent items down to fill the gap. True, that happens at C speed, but it's still best to avoid it if you can.
@piRSquared As a rule of thumb, yes, because doing pop in a loop over a list of size n is O(n²) for the whole loop instead of O(n). But it can be worthwhile to do timeit tests with real data, since the C speed can make a big difference.
n [18]: test = [(r, r) for r in range(100000)]
In [19]: %timeit [el[1] for el in test]
4.87 ms ± 296 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)
In [20]: %timeit [i for _, i in test]
3.88 ms ± 124 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)
It looks like UNPACK_SEQUENCE is just doing 'n' stack pushes, which get popped by the STORE_FASTs. I just checked and it is the same with 5-tuples as with 2-tuples
So I guess for something like in this question if you wanted a list comp to convert all those to floats, one could use: [float(f) for f, in x] instead of [float(f[0]) for f in x] - although that trailing comma always look awkward
@MuhammadNouman - if your text included "how how how are you", what would you want to match? Everything from the first 'how' to 'you', or from the last 'how'?
@WaqasAhmed There's noone who'll respond to a statement like "I need help", no. But if you tell us what you need help with, then you'll probably have more luck.
waqas61@waqas:/var/www/devcode/PY$ python -m SimpleHTTPServer Traceback (most recent call last): File "/usr/lib/python2.7/runpy.py", line 162, in _run_module_as_main "__main__", fname, loader, pkg_name) File "/usr/lib/python2.7/runpy.py", line 72, in _run_code exec code in run_globals File "/usr/lib/python2.7/SimpleHTTPServer.py", line 230, in <module> test() File "/usr/lib/python2.7/SimpleHTTPServer.py", line 226, in test BaseHTTPServer.test(HandlerClass, ServerClass) File "/usr/lib/python2.7/BaseHTTPServer.py", line 595, in test
@WaqasAhmed Please be aware that SimpleHTTPServer is a simple server. It has virtually no security features, and you should only use it on your LAN. Don't try to use it on the actual internet!
@WaqasAhmed The modern way would be to use a Web framework. But if it's a simple Web page, and a simple form, you could do it the old-fashioned way with CGI.
@WaqasAhmed Note that the cgi module just deals with the interaction between your Web page and your Python CGI script, it knows nothing about databases.
this is my Python3 project hiearchy:
projet
\
script.py
web
\
index.html
From script.py, I would like to run a http server which serve the content of the web folder.
Here is suggested this code to run a simple http server:
import http.server
import socketserver
PORT = 8000
Han...
@WaqasAhmed That's for Python 3. And if you want it to be able to deal with a submitted form, then you need to tell it to use CGI. As khajvah said, you need to do more research. Then come back when you have a clear idea of what you're doing, and you have specific questions.
Madison Nicole "Maddie" Ziegler (born September 30, 2002) is an American dancer, actress and model. She first became known for appearing in Lifetime's reality show Dance Moms from 2011 (at age 8) until 2016. From 2014 to 2016, she gained wider fame for starring in five music videos by Sia, including "Chandelier" and "Elastic Heart", which cumulatively have attracted more than 3.4 billion views on YouTube. Ziegler has guest-starred on scripted shows, danced on various TV shows and at concerts, and has been seen on magazine covers and in feature articles. She has modeled for Capezio, Ralph Lauren...