qid
int64
46k
74.7M
question
stringlengths
54
37.8k
date
stringlengths
10
10
metadata
listlengths
3
3
response_j
stringlengths
17
26k
response_k
stringlengths
26
26k
53,201,387
I am trying to write python code that organizes n-dimensional data into bins. To do this, I'm initializing a list of empty lists using the following function, which takes an array with the number of bins for each dimension as an argument: ``` def empties(b): invB = np.flip(b, axis=0) empty = [] for b in ...
2018/11/08
[ "https://Stackoverflow.com/questions/53201387", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4976543/" ]
You can `reduce` into an array, iterating over each subarray, and then over each split number from the subarray items: ```js const a = [ ["1.31069258855609,103.848649478524", "1.31138534529796,103.848923050526"], ["1.31213221536436,103.848328363879", "1.31288473199114,103.849575392632"] ]; const [d, e] = a.red...
One approach to this problem would be to take advantage of the ordering of number values in your string arrays. First flatten the two arrays into a single array, and then reduce the result - per iteration of the reduce operation, split a string by `,` into it's two parts, and then put the number value for each part i...
53,201,387
I am trying to write python code that organizes n-dimensional data into bins. To do this, I'm initializing a list of empty lists using the following function, which takes an array with the number of bins for each dimension as an argument: ``` def empties(b): invB = np.flip(b, axis=0) empty = [] for b in ...
2018/11/08
[ "https://Stackoverflow.com/questions/53201387", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4976543/" ]
You can `reduce` into an array, iterating over each subarray, and then over each split number from the subarray items: ```js const a = [ ["1.31069258855609,103.848649478524", "1.31138534529796,103.848923050526"], ["1.31213221536436,103.848328363879", "1.31288473199114,103.849575392632"] ]; const [d, e] = a.red...
Please check if the following code matches your requirement. ``` function test3(a) { let result = []; for (let i=0; i<a.length; i++) { let subArr = []; for (let j=0; j<a[i].length; j++) { let splits = a[i][j].split(','); subArr.push(splits[0]); subArr.push(splits[1]); } result.push(subArr); } cons...
53,201,387
I am trying to write python code that organizes n-dimensional data into bins. To do this, I'm initializing a list of empty lists using the following function, which takes an array with the number of bins for each dimension as an argument: ``` def empties(b): invB = np.flip(b, axis=0) empty = [] for b in ...
2018/11/08
[ "https://Stackoverflow.com/questions/53201387", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4976543/" ]
You can `reduce` into an array, iterating over each subarray, and then over each split number from the subarray items: ```js const a = [ ["1.31069258855609,103.848649478524", "1.31138534529796,103.848923050526"], ["1.31213221536436,103.848328363879", "1.31288473199114,103.849575392632"] ]; const [d, e] = a.red...
Heres a quick and dirty way of doing, basically recursively look through the array until you find a string, once you have one split it at the comma, then add the results to two different arrays. Finally, return the two arrays. ```js var a = [ [ "1.31069258855609,103.848649478524", "1.31138534529796,103.848923050...
53,201,387
I am trying to write python code that organizes n-dimensional data into bins. To do this, I'm initializing a list of empty lists using the following function, which takes an array with the number of bins for each dimension as an argument: ``` def empties(b): invB = np.flip(b, axis=0) empty = [] for b in ...
2018/11/08
[ "https://Stackoverflow.com/questions/53201387", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4976543/" ]
You can `reduce` into an array, iterating over each subarray, and then over each split number from the subarray items: ```js const a = [ ["1.31069258855609,103.848649478524", "1.31138534529796,103.848923050526"], ["1.31213221536436,103.848328363879", "1.31288473199114,103.849575392632"] ]; const [d, e] = a.red...
Here's another solution using `map`, `flat` and `reduce`. The idea is to get one continuous array of all the numbers and then add alternating numbers to 2 different arrays using `reduce`: ```js const a = [ ["1.31069258855609,103.848649478524", "1.31138534529796,103.848923050526"], ["1.31213221536436,103.84832836...
53,201,387
I am trying to write python code that organizes n-dimensional data into bins. To do this, I'm initializing a list of empty lists using the following function, which takes an array with the number of bins for each dimension as an argument: ``` def empties(b): invB = np.flip(b, axis=0) empty = [] for b in ...
2018/11/08
[ "https://Stackoverflow.com/questions/53201387", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4976543/" ]
One approach to this problem would be to take advantage of the ordering of number values in your string arrays. First flatten the two arrays into a single array, and then reduce the result - per iteration of the reduce operation, split a string by `,` into it's two parts, and then put the number value for each part i...
Please check if the following code matches your requirement. ``` function test3(a) { let result = []; for (let i=0; i<a.length; i++) { let subArr = []; for (let j=0; j<a[i].length; j++) { let splits = a[i][j].split(','); subArr.push(splits[0]); subArr.push(splits[1]); } result.push(subArr); } cons...
53,201,387
I am trying to write python code that organizes n-dimensional data into bins. To do this, I'm initializing a list of empty lists using the following function, which takes an array with the number of bins for each dimension as an argument: ``` def empties(b): invB = np.flip(b, axis=0) empty = [] for b in ...
2018/11/08
[ "https://Stackoverflow.com/questions/53201387", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4976543/" ]
One approach to this problem would be to take advantage of the ordering of number values in your string arrays. First flatten the two arrays into a single array, and then reduce the result - per iteration of the reduce operation, split a string by `,` into it's two parts, and then put the number value for each part i...
Here's another solution using `map`, `flat` and `reduce`. The idea is to get one continuous array of all the numbers and then add alternating numbers to 2 different arrays using `reduce`: ```js const a = [ ["1.31069258855609,103.848649478524", "1.31138534529796,103.848923050526"], ["1.31213221536436,103.84832836...
53,201,387
I am trying to write python code that organizes n-dimensional data into bins. To do this, I'm initializing a list of empty lists using the following function, which takes an array with the number of bins for each dimension as an argument: ``` def empties(b): invB = np.flip(b, axis=0) empty = [] for b in ...
2018/11/08
[ "https://Stackoverflow.com/questions/53201387", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4976543/" ]
Heres a quick and dirty way of doing, basically recursively look through the array until you find a string, once you have one split it at the comma, then add the results to two different arrays. Finally, return the two arrays. ```js var a = [ [ "1.31069258855609,103.848649478524", "1.31138534529796,103.848923050...
Please check if the following code matches your requirement. ``` function test3(a) { let result = []; for (let i=0; i<a.length; i++) { let subArr = []; for (let j=0; j<a[i].length; j++) { let splits = a[i][j].split(','); subArr.push(splits[0]); subArr.push(splits[1]); } result.push(subArr); } cons...
53,201,387
I am trying to write python code that organizes n-dimensional data into bins. To do this, I'm initializing a list of empty lists using the following function, which takes an array with the number of bins for each dimension as an argument: ``` def empties(b): invB = np.flip(b, axis=0) empty = [] for b in ...
2018/11/08
[ "https://Stackoverflow.com/questions/53201387", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4976543/" ]
Heres a quick and dirty way of doing, basically recursively look through the array until you find a string, once you have one split it at the comma, then add the results to two different arrays. Finally, return the two arrays. ```js var a = [ [ "1.31069258855609,103.848649478524", "1.31138534529796,103.848923050...
Here's another solution using `map`, `flat` and `reduce`. The idea is to get one continuous array of all the numbers and then add alternating numbers to 2 different arrays using `reduce`: ```js const a = [ ["1.31069258855609,103.848649478524", "1.31138534529796,103.848923050526"], ["1.31213221536436,103.84832836...
39,290,932
How to change python code to **.exe** file using microsoft Visual Studio 2015 without installing any package? Under "Build" button, there is no convert to **.exe** file.
2016/09/02
[ "https://Stackoverflow.com/questions/39290932", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6737263/" ]
Here is the complete fix for the issue: ``` private async Task<IEnumerable<byte[]>> GetAttachmentsAsByteArrayAsync(Activity activity) { var attachments = activity?.Attachments? .Where(attachment => attachment.ContentUrl != null) .Select(c => Tuple.Create(c.ContentType, c.ContentUrl)); ...
<https://github.com/Microsoft/BotBuilder/issues/662#issuecomment-232223965> you mean this fix? Did this work out for you?
39,290,932
How to change python code to **.exe** file using microsoft Visual Studio 2015 without installing any package? Under "Build" button, there is no convert to **.exe** file.
2016/09/02
[ "https://Stackoverflow.com/questions/39290932", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6737263/" ]
Here is the complete fix for the issue: ``` private async Task<IEnumerable<byte[]>> GetAttachmentsAsByteArrayAsync(Activity activity) { var attachments = activity?.Attachments? .Where(attachment => attachment.ContentUrl != null) .Select(c => Tuple.Create(c.ContentType, c.ContentUrl)); ...
I am using BotFramework with Node.js and received the same error. Finally i found a workaround. I commented below lines in ChatConnector.js and its working fine for me now. ```js if (isEmulator && decoded_1.payload.appid != this.settings.appId) { logger.error('ChatConnector: receive - invalid token. Requested...
39,290,932
How to change python code to **.exe** file using microsoft Visual Studio 2015 without installing any package? Under "Build" button, there is no convert to **.exe** file.
2016/09/02
[ "https://Stackoverflow.com/questions/39290932", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6737263/" ]
<https://github.com/Microsoft/BotBuilder/issues/662#issuecomment-232223965> you mean this fix? Did this work out for you?
I am using BotFramework with Node.js and received the same error. Finally i found a workaround. I commented below lines in ChatConnector.js and its working fine for me now. ```js if (isEmulator && decoded_1.payload.appid != this.settings.appId) { logger.error('ChatConnector: receive - invalid token. Requested...
16,002,862
I'm rather new at using python and especially numpy, and matplotlib. Running the code below (which works fine without the `\frac{}{}` part) yields the error: ``` Normalized Distance in Chamber ($ rac{x}{L}$) ^ Expected end of text (at char 32), (line:1, col:33) ...
2013/04/14
[ "https://Stackoverflow.com/questions/16002862", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1411736/" ]
In many languages, backslash-letter is a way to enter otherwise hard-to-type characters. In this case it's a "form feed". Examples: ``` \n — newline \r — carriage return \t — tab character \b — backspace ``` To disable that, you either need to escape the backslash itself (backslash-backslash is a backslash) ``` 'No...
`"\f"` is a form-feed character in Python. TeX never sees the backslash because Python interprets the `\f` in your Python source, before the string is sent to TeX. You can either double the backslash, or make your string a raw string by using `r'Normalized Distance ... etc.'`.
16,002,862
I'm rather new at using python and especially numpy, and matplotlib. Running the code below (which works fine without the `\frac{}{}` part) yields the error: ``` Normalized Distance in Chamber ($ rac{x}{L}$) ^ Expected end of text (at char 32), (line:1, col:33) ...
2013/04/14
[ "https://Stackoverflow.com/questions/16002862", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1411736/" ]
In many languages, backslash-letter is a way to enter otherwise hard-to-type characters. In this case it's a "form feed". Examples: ``` \n — newline \r — carriage return \t — tab character \b — backspace ``` To disable that, you either need to escape the backslash itself (backslash-backslash is a backslash) ``` 'No...
You have to add an `r` front of the string to avoid parsing the `\f`.
16,002,862
I'm rather new at using python and especially numpy, and matplotlib. Running the code below (which works fine without the `\frac{}{}` part) yields the error: ``` Normalized Distance in Chamber ($ rac{x}{L}$) ^ Expected end of text (at char 32), (line:1, col:33) ...
2013/04/14
[ "https://Stackoverflow.com/questions/16002862", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1411736/" ]
`"\f"` is a form-feed character in Python. TeX never sees the backslash because Python interprets the `\f` in your Python source, before the string is sent to TeX. You can either double the backslash, or make your string a raw string by using `r'Normalized Distance ... etc.'`.
You have to add an `r` front of the string to avoid parsing the `\f`.
31,438,147
it is my first post on stackoverflow so please go easy on me! :) I am also relatively new to python so bear with me :) With all that said here is my issue: I am writing a bit of code for fun which calls an API and grabs the latest Bitcoin Nonce data. I have managed to do this fine, however now I want to be able to sav...
2015/07/15
[ "https://Stackoverflow.com/questions/31438147", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5120590/" ]
Not entirely. It's right that the rules are only based on classes, and it does not matter if it is the same instance or another instance and that was basically your question. However, you made a mistake about *protected* in general. From the documentation: > > Members declared protected can be accessed only within t...
Yes, it's right. The visibility rules are based only on classes, instances have no impact. So if a class has access to a particular member in the same instance, it also has access to that member in other instances of that class. It's not a quirk, it's a deliberate design choice, similar to many other OO languages (I...
52,033,549
I have a csv file mentioned as below screen shot ... [![enter image description here](https://i.stack.imgur.com/WAVzb.png)](https://i.stack.imgur.com/WAVzb.png) and i want to convert the whole file in the below format in python. [![enter image description here](https://i.stack.imgur.com/ladmh.png)](https://i.stack.i...
2018/08/27
[ "https://Stackoverflow.com/questions/52033549", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8966278/" ]
You can try this after reading your CSV file correct file path. ``` import pandas as pd df = pd.read_csv("path/to/file", names=["Sentence", "Value"]) result = [(row["Sentence"], row["Value"]) for index, row in df.iterrows()] print(result) ```
It's a single line using `apply()` method of dataframe `df.apply(lambda x: x.tolist(), axis=1)` OR `df.values.tolist()` will also work
2,137,619
Is it possible to implement in Scala something equivalent to the Python `yield` statement where it remembers the local state of the function where it is used and "yields" the next value each time it is called? I wanted to have something like this to convert a recursive function into an iterator. Sort of like this: ``...
2010/01/26
[ "https://Stackoverflow.com/questions/2137619", "https://Stackoverflow.com", "https://Stackoverflow.com/users/257449/" ]
While Python generators are cool, trying to duplicate them really isn't the best way to go about in Scala. For instance, the following code does the equivalent job to what you want: ```scala def classStream(clazz: Class[_]): Stream[Class[_]] = clazz match { case null => Stream.empty case _ => ( clazz #:: ...
To do this in a general way, I think you need the [continuations plugin](http://blog.richdougherty.com/search/label/continuations). A naive implementation (freehand, not compiled/checked): ``` def iterator = new { private[this] var done = false // Define your yielding state here // This generator yields: 3, 13...
2,137,619
Is it possible to implement in Scala something equivalent to the Python `yield` statement where it remembers the local state of the function where it is used and "yields" the next value each time it is called? I wanted to have something like this to convert a recursive function into an iterator. Sort of like this: ``...
2010/01/26
[ "https://Stackoverflow.com/questions/2137619", "https://Stackoverflow.com", "https://Stackoverflow.com/users/257449/" ]
Another continuations plugin based solution, this time with a more or less encapsulated Generator type, ``` import scala.continuations._ import scala.continuations.ControlContext._ object Test { def loopWhile(cond: =>Boolean)(body: =>(Unit @suspendable)): Unit @suspendable = { if (cond) { body loop...
To do this in a general way, I think you need the [continuations plugin](http://blog.richdougherty.com/search/label/continuations). A naive implementation (freehand, not compiled/checked): ``` def iterator = new { private[this] var done = false // Define your yielding state here // This generator yields: 3, 13...
2,137,619
Is it possible to implement in Scala something equivalent to the Python `yield` statement where it remembers the local state of the function where it is used and "yields" the next value each time it is called? I wanted to have something like this to convert a recursive function into an iterator. Sort of like this: ``...
2010/01/26
[ "https://Stackoverflow.com/questions/2137619", "https://Stackoverflow.com", "https://Stackoverflow.com/users/257449/" ]
To do this in a general way, I think you need the [continuations plugin](http://blog.richdougherty.com/search/label/continuations). A naive implementation (freehand, not compiled/checked): ``` def iterator = new { private[this] var done = false // Define your yielding state here // This generator yields: 3, 13...
[Dsl.scala](https://github.com/ThoughtWorksInc/Dsl.scala) is what you are looking for. Suppose you want to create a random number generator. The generated numbers should be stored in a lazily evaluated infinite stream, which can be built with the help of our built-in domain-specific keyword `Yield`. ``` import com.th...
2,137,619
Is it possible to implement in Scala something equivalent to the Python `yield` statement where it remembers the local state of the function where it is used and "yields" the next value each time it is called? I wanted to have something like this to convert a recursive function into an iterator. Sort of like this: ``...
2010/01/26
[ "https://Stackoverflow.com/questions/2137619", "https://Stackoverflow.com", "https://Stackoverflow.com/users/257449/" ]
While Python generators are cool, trying to duplicate them really isn't the best way to go about in Scala. For instance, the following code does the equivalent job to what you want: ```scala def classStream(clazz: Class[_]): Stream[Class[_]] = clazz match { case null => Stream.empty case _ => ( clazz #:: ...
Another continuations plugin based solution, this time with a more or less encapsulated Generator type, ``` import scala.continuations._ import scala.continuations.ControlContext._ object Test { def loopWhile(cond: =>Boolean)(body: =>(Unit @suspendable)): Unit @suspendable = { if (cond) { body loop...
2,137,619
Is it possible to implement in Scala something equivalent to the Python `yield` statement where it remembers the local state of the function where it is used and "yields" the next value each time it is called? I wanted to have something like this to convert a recursive function into an iterator. Sort of like this: ``...
2010/01/26
[ "https://Stackoverflow.com/questions/2137619", "https://Stackoverflow.com", "https://Stackoverflow.com/users/257449/" ]
While Python generators are cool, trying to duplicate them really isn't the best way to go about in Scala. For instance, the following code does the equivalent job to what you want: ```scala def classStream(clazz: Class[_]): Stream[Class[_]] = clazz match { case null => Stream.empty case _ => ( clazz #:: ...
Scala's for-loop of the form `for (e <- Producer) f(e)` translates into a `foreach` call, and not directly into `iterator` / `next`. In the `foreach` we don't need to linearize objects' creations and have them in one place, as it would be needed for iterator's `next`. The consumer-function `f` can be inserted multiple...
2,137,619
Is it possible to implement in Scala something equivalent to the Python `yield` statement where it remembers the local state of the function where it is used and "yields" the next value each time it is called? I wanted to have something like this to convert a recursive function into an iterator. Sort of like this: ``...
2010/01/26
[ "https://Stackoverflow.com/questions/2137619", "https://Stackoverflow.com", "https://Stackoverflow.com/users/257449/" ]
While Python generators are cool, trying to duplicate them really isn't the best way to go about in Scala. For instance, the following code does the equivalent job to what you want: ```scala def classStream(clazz: Class[_]): Stream[Class[_]] = clazz match { case null => Stream.empty case _ => ( clazz #:: ...
[Dsl.scala](https://github.com/ThoughtWorksInc/Dsl.scala) is what you are looking for. Suppose you want to create a random number generator. The generated numbers should be stored in a lazily evaluated infinite stream, which can be built with the help of our built-in domain-specific keyword `Yield`. ``` import com.th...
2,137,619
Is it possible to implement in Scala something equivalent to the Python `yield` statement where it remembers the local state of the function where it is used and "yields" the next value each time it is called? I wanted to have something like this to convert a recursive function into an iterator. Sort of like this: ``...
2010/01/26
[ "https://Stackoverflow.com/questions/2137619", "https://Stackoverflow.com", "https://Stackoverflow.com/users/257449/" ]
Another continuations plugin based solution, this time with a more or less encapsulated Generator type, ``` import scala.continuations._ import scala.continuations.ControlContext._ object Test { def loopWhile(cond: =>Boolean)(body: =>(Unit @suspendable)): Unit @suspendable = { if (cond) { body loop...
Scala's for-loop of the form `for (e <- Producer) f(e)` translates into a `foreach` call, and not directly into `iterator` / `next`. In the `foreach` we don't need to linearize objects' creations and have them in one place, as it would be needed for iterator's `next`. The consumer-function `f` can be inserted multiple...
2,137,619
Is it possible to implement in Scala something equivalent to the Python `yield` statement where it remembers the local state of the function where it is used and "yields" the next value each time it is called? I wanted to have something like this to convert a recursive function into an iterator. Sort of like this: ``...
2010/01/26
[ "https://Stackoverflow.com/questions/2137619", "https://Stackoverflow.com", "https://Stackoverflow.com/users/257449/" ]
Another continuations plugin based solution, this time with a more or less encapsulated Generator type, ``` import scala.continuations._ import scala.continuations.ControlContext._ object Test { def loopWhile(cond: =>Boolean)(body: =>(Unit @suspendable)): Unit @suspendable = { if (cond) { body loop...
[Dsl.scala](https://github.com/ThoughtWorksInc/Dsl.scala) is what you are looking for. Suppose you want to create a random number generator. The generated numbers should be stored in a lazily evaluated infinite stream, which can be built with the help of our built-in domain-specific keyword `Yield`. ``` import com.th...
2,137,619
Is it possible to implement in Scala something equivalent to the Python `yield` statement where it remembers the local state of the function where it is used and "yields" the next value each time it is called? I wanted to have something like this to convert a recursive function into an iterator. Sort of like this: ``...
2010/01/26
[ "https://Stackoverflow.com/questions/2137619", "https://Stackoverflow.com", "https://Stackoverflow.com/users/257449/" ]
Scala's for-loop of the form `for (e <- Producer) f(e)` translates into a `foreach` call, and not directly into `iterator` / `next`. In the `foreach` we don't need to linearize objects' creations and have them in one place, as it would be needed for iterator's `next`. The consumer-function `f` can be inserted multiple...
[Dsl.scala](https://github.com/ThoughtWorksInc/Dsl.scala) is what you are looking for. Suppose you want to create a random number generator. The generated numbers should be stored in a lazily evaluated infinite stream, which can be built with the help of our built-in domain-specific keyword `Yield`. ``` import com.th...
69,978,383
everyone, beforehand - I'm a bloody but motivated developer beginner. I am currently trying to react to simple events (click on a button) in the HTML code in my Django project. Unfortunately without success ... HTML: ``` <form> {% csrf_token %} <button id="CSVDownload" type="button">CSV Download!</button> </...
2021/11/15
[ "https://Stackoverflow.com/questions/69978383", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17420473/" ]
You should be able to use ``` delete a,b from `t ``` to delete in place (The backtick implies in place). Alternatively, for more flexibility you could use the functional form; ``` ![`t;();0b;`a`b] ```
The simplest way to achieve column deletion in place is using qSQL: `t:([]a:1 2 3;b:4 5 6;c:`d`e`f)` `delete a,b from `t` -- here, the backtick before `t` makes the change in place. ``` q)t c - d e f ```
69,978,383
everyone, beforehand - I'm a bloody but motivated developer beginner. I am currently trying to react to simple events (click on a button) in the HTML code in my Django project. Unfortunately without success ... HTML: ``` <form> {% csrf_token %} <button id="CSVDownload" type="button">CSV Download!</button> </...
2021/11/15
[ "https://Stackoverflow.com/questions/69978383", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17420473/" ]
The simplest way to achieve column deletion in place is using qSQL: `t:([]a:1 2 3;b:4 5 6;c:`d`e`f)` `delete a,b from `t` -- here, the backtick before `t` makes the change in place. ``` q)t c - d e f ```
Michael & Kyle have covered the q-SQL options; for completeness, here are a couple of other options using `_`: Using `_` as in your question, you can re-assign this back to t e.g. ``` t:`a`b _ t ``` You can also use `.` amend with an empty list of indexes i.e. "[amend entire](https://code.kx.com/q/ref/amend/#amend-...
69,978,383
everyone, beforehand - I'm a bloody but motivated developer beginner. I am currently trying to react to simple events (click on a button) in the HTML code in my Django project. Unfortunately without success ... HTML: ``` <form> {% csrf_token %} <button id="CSVDownload" type="button">CSV Download!</button> </...
2021/11/15
[ "https://Stackoverflow.com/questions/69978383", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17420473/" ]
You should be able to use ``` delete a,b from `t ``` to delete in place (The backtick implies in place). Alternatively, for more flexibility you could use the functional form; ``` ![`t;();0b;`a`b] ```
Michael & Kyle have covered the q-SQL options; for completeness, here are a couple of other options using `_`: Using `_` as in your question, you can re-assign this back to t e.g. ``` t:`a`b _ t ``` You can also use `.` amend with an empty list of indexes i.e. "[amend entire](https://code.kx.com/q/ref/amend/#amend-...
45,096,654
I recently signed up and started playing with GAE for python. I was able to get their standard/flask/hello\_world project. But, when I tried to upload a simple cron job following the instructions at <https://cloud.google.com/appengine/docs/standard/python/config/cron>, I get an "Internal Server Error". My cron.yaml `...
2017/07/14
[ "https://Stackoverflow.com/questions/45096654", "https://Stackoverflow.com", "https://Stackoverflow.com/users/593644/" ]
I was having this problem as well, at about the same timeline. Without any changes, the deploy worked this morning, so my guess is that this was a transient server problem on Google's part.
I was just struggling with this same issue. In my case, I am using the PHP standard environment and kept receiving the '500 Internal Server Error' when I tried to publish our cron.yaml file from the Google Cloud SDK with the command: ``` gcloud app deploy cron.yaml --project {PROJECT_NAME} ``` To fix it, I did the f...
74,041,729
I have a dataset like this ``` ID Year Day 1 2001 150 2 2001 140 3 2001 120 3 2002 160 3 2002 160 3 2017 75 3 2017 75 4 2017 80 ``` I would like to drop the duplicates within each year, but keep those were the year differs. End result would be...
2022/10/12
[ "https://Stackoverflow.com/questions/74041729", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12546311/" ]
add 'year' in your subset. ``` data.drop_duplicates(subset = ['ID','Year'], keep = 'first') ``` ``` ID Year Day 0 1 2001 150 1 2 2001 140 2 3 2001 120 3 3 2002 160 5 3 2017 75 7 4 2017 80 ```
Another possible solution: ``` df.groupby('Year').apply(lambda g: g.drop_duplicates()).reset_index(drop=True) ``` Output: ``` ID Year Day 0 1 2001 150 1 2 2001 140 2 3 2001 120 3 3 2002 160 4 3 2017 75 5 4 2017 80 ```
57,015,932
I'm developing an GUI for multi-robot system using ROS, but i'm freezing in the last thing i want in my interface: embedding the RVIZ, GMAPPING or another screen in my application. I already put an terminal in the interface, but i can't get around of how to add an external application window to my app. I know that PyQt...
2019/07/13
[ "https://Stackoverflow.com/questions/57015932", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11595480/" ]
Solved it! just pass the style to the scrollableTabView style={{width: '100%' }}
Solved it! Replace DefaultTabBar with ScrollableTabBar (don't forget to import it)
27,780,868
I need to use Backpropagation Neural Netwrok for multiclass classification purposes in my application. I have found [this code](http://danielfrg.com/blog/2013/07/03/basic-neural-network-python/#disqus_thread) and try to adapt it to my needs. It is based on the lections of Machine Learning in Coursera from Andrew Ng. I...
2015/01/05
[ "https://Stackoverflow.com/questions/27780868", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4202221/" ]
Try `$eval` on `attr.target` like ``` var data = $scope.$eval($attrs.target) ``` Or if your data is dynamic you can $watch the attr ``` var data = []; $scope.$watch($attrs.target, function(newValue, oldValue){ data = newValue; }) ``` Also correct your controller injection like below, else if you will get error...
What I went with was removing the `target` attribute altogether, and instead broadcasting on the `$rootScope`. Directive: ``` this.foo = function(){ $rootScope.$broadcast('sortButtons', { predicate: 'foo', reverse: false }); }; ``` Controller: ``` $rootScope.$on('sortButtons', function(e...
55,050,699
### Task I have a text file with alphanumeric filenames: ``` \abc1.txt. \abc2.txt \abc3.txt \abcde3.txt \Zxcv1.txt \mnbd2.txt \dhtdv.txt ``` I need to extract all `.txt` extensions from the file, which will be in the same line and also different line in the file in python. ### Desired Output: ...
2019/03/07
[ "https://Stackoverflow.com/questions/55050699", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11167162/" ]
Another way to do this, is to wrap the `CupertinoDatePicker` in `CupertinoTheme`. ``` CupertinoTheme( data: CupertinoThemeData( textTheme: CupertinoTextThemeData( dateTimePickerTextStyle: TextStyle( fontSize: 16, ), ), ), child: CupertinoDatePicker(...
Finally got it, works as expected. ``` DefaultTextStyle.merge( style: TextStyle(fontSize: 20), child: CupertinoDatePicker(....) ) ```
45,300,287
I'm new in python programming and I'm having some issues in developing a specific part of my GUI with Tkinter. What I'm trying to do is, a space where the user could enter (type) his math equation and the software make the calculation with the variables previously calculated. I've found a lot of calculators for Tkin...
2017/07/25
[ "https://Stackoverflow.com/questions/45300287", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8267211/" ]
For a start webview consumes memory because it load has to load and render html data. Rather than using a webview in a recycler view, I think it would be better if you implemented it either of these two ways: 1. You handle the list of data in html and send it into the webview and remove the recycler view completely 2....
This problem can arrive for many possible reasons * When you scroll very fast Recyclerview is purely based on Inflating the view minimal times and reusing the existing views. This means that while you are scrolling when a view(An item) exits your screen the same view is bought below just by changing its contents.When ...
45,300,287
I'm new in python programming and I'm having some issues in developing a specific part of my GUI with Tkinter. What I'm trying to do is, a space where the user could enter (type) his math equation and the software make the calculation with the variables previously calculated. I've found a lot of calculators for Tkin...
2017/07/25
[ "https://Stackoverflow.com/questions/45300287", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8267211/" ]
This problem can arrive for many possible reasons * When you scroll very fast Recyclerview is purely based on Inflating the view minimal times and reusing the existing views. This means that while you are scrolling when a view(An item) exits your screen the same view is bought below just by changing its contents.When ...
I solved this problem by floating a WebView in a up layer of RecyclerView, meanwhile placing a HOLDER view in RecyclerView. And then I register an listener to the scroll event of RecyclerView. I Control the position and visibility of the floating WebView
45,300,287
I'm new in python programming and I'm having some issues in developing a specific part of my GUI with Tkinter. What I'm trying to do is, a space where the user could enter (type) his math equation and the software make the calculation with the variables previously calculated. I've found a lot of calculators for Tkin...
2017/07/25
[ "https://Stackoverflow.com/questions/45300287", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8267211/" ]
This problem can arrive for many possible reasons * When you scroll very fast Recyclerview is purely based on Inflating the view minimal times and reusing the existing views. This means that while you are scrolling when a view(An item) exits your screen the same view is bought below just by changing its contents.When ...
You can try this code in `onCreateViewHolder` ``` ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); WebView web = new WebView(parent.getContext()); web.setLayoutParams(lp); ...
45,300,287
I'm new in python programming and I'm having some issues in developing a specific part of my GUI with Tkinter. What I'm trying to do is, a space where the user could enter (type) his math equation and the software make the calculation with the variables previously calculated. I've found a lot of calculators for Tkin...
2017/07/25
[ "https://Stackoverflow.com/questions/45300287", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8267211/" ]
For a start webview consumes memory because it load has to load and render html data. Rather than using a webview in a recycler view, I think it would be better if you implemented it either of these two ways: 1. You handle the list of data in html and send it into the webview and remove the recycler view completely 2....
I solved this problem by floating a WebView in a up layer of RecyclerView, meanwhile placing a HOLDER view in RecyclerView. And then I register an listener to the scroll event of RecyclerView. I Control the position and visibility of the floating WebView
45,300,287
I'm new in python programming and I'm having some issues in developing a specific part of my GUI with Tkinter. What I'm trying to do is, a space where the user could enter (type) his math equation and the software make the calculation with the variables previously calculated. I've found a lot of calculators for Tkin...
2017/07/25
[ "https://Stackoverflow.com/questions/45300287", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8267211/" ]
For a start webview consumes memory because it load has to load and render html data. Rather than using a webview in a recycler view, I think it would be better if you implemented it either of these two ways: 1. You handle the list of data in html and send it into the webview and remove the recycler view completely 2....
You can try this code in `onCreateViewHolder` ``` ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); WebView web = new WebView(parent.getContext()); web.setLayoutParams(lp); ...
51,927,893
So I started learning python 3 and I wanted to run a very simple code on ubuntu: ``` print type("Hello World") ^ SyntaxError: invalid syntax ``` When I tried to compile that with command python3 hello.py in terminal it gave me the error above, but when used python hello.py (I think it means to use python 2 ...
2018/08/20
[ "https://Stackoverflow.com/questions/51927893", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10140067/" ]
In Python3, `print` [was changed](https://docs.python.org/3.0/whatsnew/3.0.html#print-is-a-function) from a statement to a function (with brackets): i.e. ``` # In Python 2.x print type("Hello World") # In Python 3.x print(type("Hello World")) ```
In Python 3.x [`print()`](https://docs.python.org/3/library/functions.html#print) is a function, while in 2.x it was a statement. The correct syntax in Python 3 would be: ``` print(type("Hello World")) ```
51,927,893
So I started learning python 3 and I wanted to run a very simple code on ubuntu: ``` print type("Hello World") ^ SyntaxError: invalid syntax ``` When I tried to compile that with command python3 hello.py in terminal it gave me the error above, but when used python hello.py (I think it means to use python 2 ...
2018/08/20
[ "https://Stackoverflow.com/questions/51927893", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10140067/" ]
In Python3, `print` [was changed](https://docs.python.org/3.0/whatsnew/3.0.html#print-is-a-function) from a statement to a function (with brackets): i.e. ``` # In Python 2.x print type("Hello World") # In Python 3.x print(type("Hello World")) ```
[This is because from Python 3, `print` is a **function**, not a statement anymore.](https://sebastianraschka.com/Articles/2014_python_2_3_key_diff.html#the-print-function) Therefore, Python 3 only accepts: ```py print(type("Hello World")) ```
51,927,893
So I started learning python 3 and I wanted to run a very simple code on ubuntu: ``` print type("Hello World") ^ SyntaxError: invalid syntax ``` When I tried to compile that with command python3 hello.py in terminal it gave me the error above, but when used python hello.py (I think it means to use python 2 ...
2018/08/20
[ "https://Stackoverflow.com/questions/51927893", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10140067/" ]
In Python 3.x [`print()`](https://docs.python.org/3/library/functions.html#print) is a function, while in 2.x it was a statement. The correct syntax in Python 3 would be: ``` print(type("Hello World")) ```
[This is because from Python 3, `print` is a **function**, not a statement anymore.](https://sebastianraschka.com/Articles/2014_python_2_3_key_diff.html#the-print-function) Therefore, Python 3 only accepts: ```py print(type("Hello World")) ```
10,352,538
I am stuck with this problem for the past few hours. This is how the XML looks like ``` <xmlblock> <data1> <username>someusername</username> <id>12345</id> </data1> <data2> <username>username</username> <id>11111</id> </data1> ...
2012/04/27
[ "https://Stackoverflow.com/questions/10352538", "https://Stackoverflow.com", "https://Stackoverflow.com/users/897906/" ]
A (probably not the best) solution ``` >>> id_to_match = 12345 >>> for event, element in cElementTree.iterparse('xmlfile.xml'): ... if 'data' in element.tag: ... for data in element: ... if data.tag == 'username': ... username = data.text ... if data.tag == 'id': ... ...
If you are ok with using [minidom](http://docs.python.org/library/xml.dom.minidom.html) the following should work ``` from xml.dom import minidom doc = minidom.parseString('<xmlblock><data1><username>someusername</username><id>12345</id></data1><data2><username>username</username><id>11111</id></data2></xmlblock>') us...
10,352,538
I am stuck with this problem for the past few hours. This is how the XML looks like ``` <xmlblock> <data1> <username>someusername</username> <id>12345</id> </data1> <data2> <username>username</username> <id>11111</id> </data1> ...
2012/04/27
[ "https://Stackoverflow.com/questions/10352538", "https://Stackoverflow.com", "https://Stackoverflow.com/users/897906/" ]
A (probably not the best) solution ``` >>> id_to_match = 12345 >>> for event, element in cElementTree.iterparse('xmlfile.xml'): ... if 'data' in element.tag: ... for data in element: ... if data.tag == 'username': ... username = data.text ... if data.tag == 'id': ... ...
Here's an example using [lxml](http://lxml.de/) and [xpath](http://en.wikipedia.org/wiki/XPath) --- ``` >>> xml = ''' <xmlblock> <data1> <username>someusername</username> <id>12345</id> </data1> <data2> <username>username</username> <id...
66,910,159
Consider the below set of lists that contain two strings each. The pairing of two strings in a given list means the values they represent are equal. So item A is the same as item B and C, and so on. ``` l1 = [ 'A' , 'B' ] l2 = [ 'A' , 'C' ] l3 = [ 'B' , 'C' ] ``` What is the most efficient/pythonic way to collect...
2021/04/01
[ "https://Stackoverflow.com/questions/66910159", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3234810/" ]
I would use a defaultdict from collections so the dictionary expands and just takes whatever you throw into it. If this is a one way correspondence I would use this code (assuming you make a list of the lists) ``` dd = collections.defaultdict(list) for line in lists: dd[line[0]].append(line[1]) ``` for given se...
--- Assuming you can get a list of those lists like so: ``` [[ 'A' , 'B' ], [ 'A' , 'C' ],[ 'B' , 'C' ]] ``` This should give you the relation you want: ``` d = {} l1 = [[ 'A' , 'B' ],[ 'A' , 'C' ],[ 'B' , 'C' ]] for sublist in l1: if sublist[0] not in d.keys(): #check if first value is already a key in the...
66,910,159
Consider the below set of lists that contain two strings each. The pairing of two strings in a given list means the values they represent are equal. So item A is the same as item B and C, and so on. ``` l1 = [ 'A' , 'B' ] l2 = [ 'A' , 'C' ] l3 = [ 'B' , 'C' ] ``` What is the most efficient/pythonic way to collect...
2021/04/01
[ "https://Stackoverflow.com/questions/66910159", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3234810/" ]
I would use a defaultdict from collections so the dictionary expands and just takes whatever you throw into it. If this is a one way correspondence I would use this code (assuming you make a list of the lists) ``` dd = collections.defaultdict(list) for line in lists: dd[line[0]].append(line[1]) ``` for given se...
I have a rather long-winded answer that stores an ID if it has been added to the dict already. There must be a more efficient answer though! ``` l = [["A", "B"], ["A", "C"], ["B", "C"]] d = dict() used_list = list() for i in l: id_one, id_two = i if not id_one in used_list and id_one not in d.keys(): ...
17,039,457
I want to convert the first column of data from a text file into a list in python ``` data = open ('data.txt', 'r') data.read() ``` provides ``` '12 45\n13 46\n14 47\n15 48\n16 49\n17 50\n18 51' ``` Any help, please.
2013/06/11
[ "https://Stackoverflow.com/questions/17039457", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2473267/" ]
You can use `str.split` and a `list comprehension` here: ``` with open('data.txt') as f: lis = [int(line.split()[0]) for line in f] >>> lis [12, 13, 14, 15, 16, 17, 18] ``` If the numbers to be strings: ``` >>> with open('abc') as f: lis = [line.split()[0] for line in f] >>> lis ['12', '13', '14', '15', '...
``` import csv with open ('data.txt', 'rb') as f: print [row[0] for row in csv.reader(f, delimiter=' ')] ``` --- ``` ['12', '13', '14', '15', '16', '17', '18'] ```
27,801,200
How do i put this in a loop in python so that it keeps asking if player 1 has won the game, until it reaches the number of games in the match. i tried a while loop but it didn't work :( ``` Y="yes" N="no" PlayerOneScore=0 PlayerTwoScore=0 NoOfGamesInMatch=int(input("How many games? :- ")) while PlayerOneScore < NoOfG...
2015/01/06
[ "https://Stackoverflow.com/questions/27801200", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4424276/" ]
You can have a preRender set on the *listLabelsPage.xhtml* page you're loading ``` <f:event type="preRenderView" listener="#{yourBean.showGrowl}" /> ``` and a showGrowl method having only ``` public void showGrowl() { FacesContext context = FacesContext.getCurrentInstance(); context.addMessage(null, new FacesMe...
I post an answer to my own question in order to help another people which face the same problem like I did: ``` public String addLabelInDB() { try { //some logic to insert in db //below I set a flag on context which helps me to display a growl message only when the insertion was done wi...
27,801,200
How do i put this in a loop in python so that it keeps asking if player 1 has won the game, until it reaches the number of games in the match. i tried a while loop but it didn't work :( ``` Y="yes" N="no" PlayerOneScore=0 PlayerTwoScore=0 NoOfGamesInMatch=int(input("How many games? :- ")) while PlayerOneScore < NoOfG...
2015/01/06
[ "https://Stackoverflow.com/questions/27801200", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4424276/" ]
You can have a preRender set on the *listLabelsPage.xhtml* page you're loading ``` <f:event type="preRenderView" listener="#{yourBean.showGrowl}" /> ``` and a showGrowl method having only ``` public void showGrowl() { FacesContext context = FacesContext.getCurrentInstance(); context.addMessage(null, new FacesMe...
How about this? Make a separated redirect button which will be hit after showing msg: HTML: ``` <h:form prependId="false"> <p:growl /> <p:button outcome="gotoABC" id="rdr-btn" style="display: none;" /> <p:commandButton action="#{bean.process()}" update="@form" /> </form> ``` Bean: ``` public void proce...
27,801,200
How do i put this in a loop in python so that it keeps asking if player 1 has won the game, until it reaches the number of games in the match. i tried a while loop but it didn't work :( ``` Y="yes" N="no" PlayerOneScore=0 PlayerTwoScore=0 NoOfGamesInMatch=int(input("How many games? :- ")) while PlayerOneScore < NoOfG...
2015/01/06
[ "https://Stackoverflow.com/questions/27801200", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4424276/" ]
I post an answer to my own question in order to help another people which face the same problem like I did: ``` public String addLabelInDB() { try { //some logic to insert in db //below I set a flag on context which helps me to display a growl message only when the insertion was done wi...
How about this? Make a separated redirect button which will be hit after showing msg: HTML: ``` <h:form prependId="false"> <p:growl /> <p:button outcome="gotoABC" id="rdr-btn" style="display: none;" /> <p:commandButton action="#{bean.process()}" update="@form" /> </form> ``` Bean: ``` public void proce...
51,413,816
Before I begin, I'd like to preface that I'm relatively new to python, and haven't had to use it much before this little project of mine. I'm trying to make a twitter bot as part of an art project, and I can't seem to get tweepy to import. I'm using macOS High Sierra and Python 3.7. I first installed tweepy by using ...
2018/07/19
[ "https://Stackoverflow.com/questions/51413816", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10102844/" ]
Using `async` as an identifier [has been deprecated since Python 3.5, and became an error in Python 3.7](https://www.python.org/dev/peps/pep-0492/#deprecation-plans), because it's a keyword. This Tweepy bug was [reported on 16 Mar](https://github.com/tweepy/tweepy/issues/1017), and [fixed on 12 May](https://github.com...
In Python3.7, [`async`](https://docs.python.org/3/reference/compound_stmts.html#async) became a reserved word (as can be seen in *whats new* section [here](https://docs.python.org/3/whatsnew/3.7.html)) and therefore cannot be used as argument. This is why this `Syntax Error` is raised. That said, and following `tweet...
48,143,394
So I play a game in which I have 12 pieces of gear. Each piece of gear (for the purposes of my endeavor) has four buffs I am interested in: power, haste, critical damage, critical rating. I have a formula in which I can enter the total power, haste, CD, and CR and generate the expected damage per second output. Howev...
2018/01/08
[ "https://Stackoverflow.com/questions/48143394", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5208967/" ]
Use iterator to replace for-loop: ``` keys = ['p', 'h', 'cd', 'cr'] iter_keys = itertools.product(*([keys] * 12)) for item in iter_keys: print item ``` Output: ``` ('p', 'p', 'p', 'p', 'p', 'cr', 'cd', 'h', 'cr', 'p', 'h', 'cr') ('p', 'p', 'p', 'p', 'p', 'cr', 'cd', 'h', 'cr', 'p', 'cd', 'p') ('p', 'p', 'p', 'p...
If you have 12 nested for loops, you probably need a recursive design like this : ``` def loops (values, num, current_list): if num > 0: for v in values: loops(values, num-1, current_list+list(v)) else: print current_list loops (('a', 'b', 'c', 'd'), 12, []) ``` Then, you will p...
12,969,897
I have some questions about encoding in python 2.7. 1.The python code is as below, ``` #s = u"严" s = u'\u4e25' print 's is:', s print 'len of s is:', len(s) s1 = "a" + s print 's1 is:', s1 print 'len of s1 is:', len(s1) ``` the output is: ``` s is: 严 len of s is: 1 s1 is: a严 len of s1 is: 2 ``` I am confused tha...
2012/10/19
[ "https://Stackoverflow.com/questions/12969897", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1477871/" ]
> > I am confused that why the len of s is 1, how could 4e25 be stored in 1 byte? I also notice that USC-2 is 2-bytes long and USC-4 is 4-bytes long, why unicode string s's length is 1? > > > The whole point of unicode strings is to do this. The length of a unicode string is the number of *characters* (i.e., code ...
### Answer to Question 1: In Python versions <3.3, length for a Unicode string `u''` is the number of UTF-16 or UTF-32 code units used (depending on build flags), not the number of bytes. `\u4e25` is one code unit, but not all characters are represented by one code unit if UTF-16 (default on Windows) is used. ``` >>>...
13,623,634
Why doesn't following code print anything: ``` #!/usr/bin/python3 class test: def do_someting(self,value): print(value) return value def fun1(self): map(self.do_someting,range(10)) if __name__=="__main__": t = test() t.fun1() ``` I'm executing the above code in Python 3. I t...
2012/11/29
[ "https://Stackoverflow.com/questions/13623634", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1651941/" ]
[`map()` returns an iterator](http://docs.python.org/3/library/functions.html#map), and will not process elements until you ask it to. Turn it into a list to force all elements to be processed: ``` list(map(self.do_someting,range(10))) ``` or use `collections.deque()` with the length set to 0 to not produce a list ...
Before Python 3, map() returned a list, not an iterator. So your example would work in Python 2.7. list() creates a new list by iterating over its argument. ( list() is NOT JUST a type conversion from say tuple to list. So list(list((1,2))) returns [1,2]. ) So list(map(...)) is backwards compatible with Python 2.7.
13,623,634
Why doesn't following code print anything: ``` #!/usr/bin/python3 class test: def do_someting(self,value): print(value) return value def fun1(self): map(self.do_someting,range(10)) if __name__=="__main__": t = test() t.fun1() ``` I'm executing the above code in Python 3. I t...
2012/11/29
[ "https://Stackoverflow.com/questions/13623634", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1651941/" ]
[`map()` returns an iterator](http://docs.python.org/3/library/functions.html#map), and will not process elements until you ask it to. Turn it into a list to force all elements to be processed: ``` list(map(self.do_someting,range(10))) ``` or use `collections.deque()` with the length set to 0 to not produce a list ...
I just want to add the following: `With multiple iterables, the iterator stops when the shortest iterable is exhausted` [ <https://docs.python.org/3.4/library/functions.html#map> ] Python 2.7.6 (default, Mar 22 2014, 22:59:56) ``` >>> list(map(lambda a, b: [a, b], [1, 2, 3], ['a', 'b'])) [[1, 'a'], [2, 'b'], [3, No...
13,623,634
Why doesn't following code print anything: ``` #!/usr/bin/python3 class test: def do_someting(self,value): print(value) return value def fun1(self): map(self.do_someting,range(10)) if __name__=="__main__": t = test() t.fun1() ``` I'm executing the above code in Python 3. I t...
2012/11/29
[ "https://Stackoverflow.com/questions/13623634", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1651941/" ]
Before Python 3, map() returned a list, not an iterator. So your example would work in Python 2.7. list() creates a new list by iterating over its argument. ( list() is NOT JUST a type conversion from say tuple to list. So list(list((1,2))) returns [1,2]. ) So list(map(...)) is backwards compatible with Python 2.7.
I just want to add the following: `With multiple iterables, the iterator stops when the shortest iterable is exhausted` [ <https://docs.python.org/3.4/library/functions.html#map> ] Python 2.7.6 (default, Mar 22 2014, 22:59:56) ``` >>> list(map(lambda a, b: [a, b], [1, 2, 3], ['a', 'b'])) [[1, 'a'], [2, 'b'], [3, No...
48,055,372
I Converted a csv to list: ``` import csv with open('DataAnalizada.csv', 'rb') as f: reader = csv.reader(f) a = list(reader) ``` I need to analyze the information on that list where it is analyzed by customer groups and dates first as AAA customer on 12/27/2017, AAA on 12/28/2017, BBB on 12/27/2017, BBB on 2...
2018/01/02
[ "https://Stackoverflow.com/questions/48055372", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8717507/" ]
I thought this might lead you to what you want, however, not sure this will be totally helpful. Since you don't have a condition to filter data, I tried the following way to just get your desired output. Note, this is just a try to guide you towards pandas. `pandas` would be the best way to go about this as you could...
The Pandas package has the tools you need. However I would recommend starting with [scipy](https://www.scipy.org/about.html "scipy") and [anaconda](https://www.anaconda.com/download/#linux "anaconda") since I found installing Pandas on its own to be quite difficult.
48,055,372
I Converted a csv to list: ``` import csv with open('DataAnalizada.csv', 'rb') as f: reader = csv.reader(f) a = list(reader) ``` I need to analyze the information on that list where it is analyzed by customer groups and dates first as AAA customer on 12/27/2017, AAA on 12/28/2017, BBB on 12/27/2017, BBB on 2...
2018/01/02
[ "https://Stackoverflow.com/questions/48055372", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8717507/" ]
``` import csv from collections import namedtuple with open('DataAnalizada.csv', 'rb') as f: reader = csv.reader(f) first_col = reader.next() header = namedtuple('header', first_col) data = {} for val in reader: get_ = header(*val) if get_.Analisis == 'Estable': get...
The Pandas package has the tools you need. However I would recommend starting with [scipy](https://www.scipy.org/about.html "scipy") and [anaconda](https://www.anaconda.com/download/#linux "anaconda") since I found installing Pandas on its own to be quite difficult.
52,571,930
I have a 2D array A: ``` 28 39 52 77 80 66 7 18 24 9 97 68 ``` And a vector array of column indexes B: ``` 1 0 2 0 ``` How, in a pythonian way, using base Python or Numpy, can I select the elements from A which DO NOT correspond to the column indexes in B? I should get this 2D array wh...
2018/09/29
[ "https://Stackoverflow.com/questions/52571930", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10434696/" ]
You can make use of broadcasting and a row-wise mask to select elements not contained in your array for each row: ***Setup*** ``` B = np.array([1, 0, 2, 0]) cols = np.arange(A.shape[1]) ``` --- Now use broadcasting to create a mask, and index your array. ``` mask = B[:, None] != cols A[mask].reshape(-1, 2) ``` ...
A spin off of my answer to your other question, [Replace 2D array elements with zeros, using a column index vector](https://stackoverflow.com/questions/52573733/replace-2d-array-elements-with-zeros-using-a-column-index-vector) We can make a boolean `mask` with the same indexing used before: ``` In [124]: mask = np....
55,808,362
I have just started working with python 3.7 and I am trying to create a series e.g from 0 to 23 and repeat it. Using ``` rep1 = pd.Series(range(24)) ``` I figured out how to make the first 24 values and I wanted to "copy-paste" it many times so that the final series is the original 5 times, one after the other. The ...
2019/04/23
[ "https://Stackoverflow.com/questions/55808362", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11167002/" ]
you can try this: ``` pd.concat([rep1]*5) ``` This will repeat your series 5 times.
You could use a list to generate directly your Series. ``` rep = pd.Series(list(range(24))*5) ```
55,808,362
I have just started working with python 3.7 and I am trying to create a series e.g from 0 to 23 and repeat it. Using ``` rep1 = pd.Series(range(24)) ``` I figured out how to make the first 24 values and I wanted to "copy-paste" it many times so that the final series is the original 5 times, one after the other. The ...
2019/04/23
[ "https://Stackoverflow.com/questions/55808362", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11167002/" ]
you can try this: ``` pd.concat([rep1]*5) ``` This will repeat your series 5 times.
Another solution using [`numpy.tile`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.tile.html): ``` import numpy as np rep = pd.Series(np.tile(rep1, 5)) ```
55,808,362
I have just started working with python 3.7 and I am trying to create a series e.g from 0 to 23 and repeat it. Using ``` rep1 = pd.Series(range(24)) ``` I figured out how to make the first 24 values and I wanted to "copy-paste" it many times so that the final series is the original 5 times, one after the other. The ...
2019/04/23
[ "https://Stackoverflow.com/questions/55808362", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11167002/" ]
you can try this: ``` pd.concat([rep1]*5) ``` This will repeat your series 5 times.
If you want the repeated Series as one data object then use a pandas DataFrame for this. A DataFrame is multiple pandas Series in one object, sharing an index. So firstly I am creating a python list, of 0-23, 5 times. Then I put this into a DataFrame and optionally transpose so that I have the rows going down rather...
55,808,362
I have just started working with python 3.7 and I am trying to create a series e.g from 0 to 23 and repeat it. Using ``` rep1 = pd.Series(range(24)) ``` I figured out how to make the first 24 values and I wanted to "copy-paste" it many times so that the final series is the original 5 times, one after the other. The ...
2019/04/23
[ "https://Stackoverflow.com/questions/55808362", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11167002/" ]
Another solution using [`numpy.tile`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.tile.html): ``` import numpy as np rep = pd.Series(np.tile(rep1, 5)) ```
You could use a list to generate directly your Series. ``` rep = pd.Series(list(range(24))*5) ```
55,808,362
I have just started working with python 3.7 and I am trying to create a series e.g from 0 to 23 and repeat it. Using ``` rep1 = pd.Series(range(24)) ``` I figured out how to make the first 24 values and I wanted to "copy-paste" it many times so that the final series is the original 5 times, one after the other. The ...
2019/04/23
[ "https://Stackoverflow.com/questions/55808362", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11167002/" ]
Another solution using [`numpy.tile`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.tile.html): ``` import numpy as np rep = pd.Series(np.tile(rep1, 5)) ```
If you want the repeated Series as one data object then use a pandas DataFrame for this. A DataFrame is multiple pandas Series in one object, sharing an index. So firstly I am creating a python list, of 0-23, 5 times. Then I put this into a DataFrame and optionally transpose so that I have the rows going down rather...
6,474,923
I'm getting errors building an App store and Adhoc distributions of my project. I'm using the latest version of the three20 which I integrated into my Xcode 4 project using the given python script. The release and debug version of the project build just fine without any build errors. Here's the summary of the errors:...
2011/06/25
[ "https://Stackoverflow.com/questions/6474923", "https://Stackoverflow.com", "https://Stackoverflow.com/users/539115/" ]
I have figured out whats going on here. The python script the header search paths for three20 to: ``` $(BUILT_PRODUCTS_DIR)/../three20 $(BUILT_PRODUCTS_DIR)/../../three20 ../../libs/external/three20/Build/Products/three20 ``` These paths work fine for Debug and Release builds as the macros expand to paths without an...
It might have happened because you added these 2 new targets AFTER you use the python script to add three20 project. You will need to run the python script again to add three20 to your new targets: ``` python three20/src/scripts/ttmodule.py -p ProjectName/ProjectName.xcodeproj -c NEW_TARGET_NAME Three20 ```
35,562,234
I have a python script that displays the Date, hour and IP Address for an attack in a log file. My issue is that i need to be able to count how many attacks occur per hour per day but when i implement a count it just counts the total not what i want. **The log file looks like this:** ``` Feb 3 08:50:39 j4-be02 sshd[...
2016/02/22
[ "https://Stackoverflow.com/questions/35562234", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4671509/" ]
The python function [`groupby()`](https://docs.python.org/2/library/itertools.html#itertools.groupby) will group your items according to any criteria you specify. This code will print the number of attacks per hour, per day: ``` from itertools import groupby with open('auth.log') as myAuthlog: for key, group in ...
``` import collections from datetime import datetime as dt answer = collections.defaultdict(int) with open('path/to/logfile') as infile: for line in infile: stamp = line[:9] t = dt.strptime(stamp, "%b\t%d\t%H") answer[t] += 1 ```
70,088,746
In python I am returning numbers but I only want the last 10 numbers Ex: 221234567890 should return 1234567890 In excel it looks like: if(len(cell) > 10, right (cell,10),.. but don't know how to do this in python
2021/11/23
[ "https://Stackoverflow.com/questions/70088746", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17492723/" ]
```py a = 221234567890 result = a % 10000000000 ``` This should work for ints and ```py a = "221234567890" result = a[-10:] ``` should work for strings
``` a = '123456789abcdefg' a[-10:] ```
70,951,954
So im trying to make a script using Lexing and Parsing. I wanted to try and change the color of the texts when a user inputs something. Say in python when I do: '''print("Hello")''' It changes the color of print, string, parens, etc. I just wanted to know how to do it and/or the code to do it. Say if my user types: '...
2022/02/02
[ "https://Stackoverflow.com/questions/70951954", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18097622/" ]
You can do like this ``` import colorama from colorama import Fore print(Fore.RED + 'This text is red in color') ```
Try using colorama, or termcolor in python: Here is a link: <https://www.geeksforgeeks.org/print-colors-python-terminal/>
63,345,648
I have been able to filter all the image url from a page and displayed them one after the other ``` import requests from bs4 import BeautifulSoup article_URL = "https://medium.com/bhavaniravi/build-your-1st-python-web-app-with-flask-b039d11f101c" response = requests.get(article_URL) soup = bs4.BeautifulSoup(response....
2020/08/10
[ "https://Stackoverflow.com/questions/63345648", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8053783/" ]
There is no native javascript api that allows you to find event listeners that were added using `eventTarget.addEventListener`. You can still get events added using the `onclick` attribute whether the attribute was set using javascript or inline through html - in this case u are not getting the event listener, but you...
There is no way, to do so directly with JavaScript. However, you can use this approach and add an attribute while binding events to the elements. ```js document.getElementById('test2').addEventListener('keypress', function() { this.setAttribute("event", "yes"); console.log("foo"); } ) document.querySelecto...
67,137,419
I have started to use AWS SAM for python. When testing my functions locally I run: ``` sam build --use-container sam local start-api You can now browse to the above endpoints to invoke your functions. You do **not** need to restart/reload SAM CLI while working on your functions, changes will be reflected instantly/au...
2021/04/17
[ "https://Stackoverflow.com/questions/67137419", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6281479/" ]
I believe your goal as follows. * You want to reduce the process cost of the following script. ``` resultsSheet.hideColumns(11); resultsSheet.hideColumns(18); resultsSheet.hideColumns(19); resultsSheet.showColumns(26); resultsSheet.showColumns(27); resultsSheet.showColumns(28); resultsSheet.showColumns(...
To do this faster, you can hide and show rows in groups, with one SpreadsheetApp call required per group. For example, you can hide the seven columns listed in your code sample with this: `hideColumns_(resultSheet, [11, 18, 19, 26, 27, 28, 29]);` To show columns, use a similar pattern with `showColumns_()`. Here's th...
6,576,829
I'am looking for python async SMTP client to connect it with Torando IoLoop. I found only simple implmementation (<http://tornadogists.org/907491/>) but it's a blocking solution so it might bring performance issues. Does anyone encountered non blocking SMTP client for Tornado? Some code snippet would be also very usef...
2011/07/04
[ "https://Stackoverflow.com/questions/6576829", "https://Stackoverflow.com", "https://Stackoverflow.com/users/747179/" ]
I wrote solution based on threads and queue. One thread per tornado process. This thread is a worker, gets email from queue and then send it via SMTP. You send emails from tornado application by adding it to queue. Simple and easy. Here is sample code on GitHub: [link](https://github.com/marcinc81/quemail)
Just FYI - I just whipped up a ioloop based smtp client. While I can't say it's production tested, it will be in the near future. <https://gist.github.com/1358253>
6,576,829
I'am looking for python async SMTP client to connect it with Torando IoLoop. I found only simple implmementation (<http://tornadogists.org/907491/>) but it's a blocking solution so it might bring performance issues. Does anyone encountered non blocking SMTP client for Tornado? Some code snippet would be also very usef...
2011/07/04
[ "https://Stackoverflow.com/questions/6576829", "https://Stackoverflow.com", "https://Stackoverflow.com/users/747179/" ]
I wrote solution based on threads and queue. One thread per tornado process. This thread is a worker, gets email from queue and then send it via SMTP. You send emails from tornado application by adding it to queue. Simple and easy. Here is sample code on GitHub: [link](https://github.com/marcinc81/quemail)
<https://github.com/equeny/tornadomail> - here is my attemp to port django mail system and python smtplib to tornado ioloop. Will be happy to hear some feedback.
6,576,829
I'am looking for python async SMTP client to connect it with Torando IoLoop. I found only simple implmementation (<http://tornadogists.org/907491/>) but it's a blocking solution so it might bring performance issues. Does anyone encountered non blocking SMTP client for Tornado? Some code snippet would be also very usef...
2011/07/04
[ "https://Stackoverflow.com/questions/6576829", "https://Stackoverflow.com", "https://Stackoverflow.com/users/747179/" ]
I wrote solution based on threads and queue. One thread per tornado process. This thread is a worker, gets email from queue and then send it via SMTP. You send emails from tornado application by adding it to queue. Simple and easy. Here is sample code on GitHub: [link](https://github.com/marcinc81/quemail)
I'm not using my own SMTP server but figured this would be useful to someone: I've just had to add email sending to my app. Most of the sample python code for the web emailing services use a blocking design so I dont want to use it. Mailchimp's [Mandrill](https://mandrillapp.com/) uses HTTP POST requests so it can wo...
6,576,829
I'am looking for python async SMTP client to connect it with Torando IoLoop. I found only simple implmementation (<http://tornadogists.org/907491/>) but it's a blocking solution so it might bring performance issues. Does anyone encountered non blocking SMTP client for Tornado? Some code snippet would be also very usef...
2011/07/04
[ "https://Stackoverflow.com/questions/6576829", "https://Stackoverflow.com", "https://Stackoverflow.com/users/747179/" ]
I wrote solution based on threads and queue. One thread per tornado process. This thread is a worker, gets email from queue and then send it via SMTP. You send emails from tornado application by adding it to queue. Simple and easy. Here is sample code on GitHub: [link](https://github.com/marcinc81/quemail)
I was looking for the solution to the same problem at work. Since there was no readily available solution, I ported Python smtplib to implementation based on tornado non-blocking IOStream. The syntax follows that of smtplib as close as possible. ``` # create SMTP client s = SMTPAsync() yield s.connect('your.email.ho...
51,307,411
I'm trying to make an api for Pokemon, and I was thinking of packaging it, but no matter what I do, as soon as I try to import from this file, it comes up with this error. ``` Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/home/student/anaconda3/lib/python3.6/site-packages/pokeapi/__...
2018/07/12
[ "https://Stackoverflow.com/questions/51307411", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4503723/" ]
I think the `if btnState == 2` statement is in the wrong block. Also, what is `questionNumber`, when will it be incremented? How does it relate to `self.turn`? You could try this: ``` @IBAction func btnUncoverQuestion(_ sender: RoundedButton) { btnUncoverQuestion.setTitle(questionArray?[questionNumber].title ?? ...
Please use tag for different event.Example in 1st press you set the button.tag = 100 and 2nd press set the tag 200. Check the tag in button action: ``` @IBAction func btnAction(_ sender: UIButton) { switch sender.tag { case 100: //your action sender.tag = 200 case 200: //your acti...
22,391,419
what is the difference between curly brace and square bracket in python? ``` A ={1,2} B =[1,2] ``` when I print `A` and `B` on my terminal, they made no difference. Is it real? And sometimes, I noticed some code use `{}` and `[]` to initialize different variables. E.g. `A=[]`, `B={}` Is there any difference ther...
2014/03/13
[ "https://Stackoverflow.com/questions/22391419", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2911587/" ]
Curly braces create [dictionaries](https://docs.python.org/3/library/stdtypes.html#mapping-types-dict) or [sets](https://docs.python.org/3/library/stdtypes.html#set-types-set-frozenset). Square brackets create [lists](https://docs.python.org/3/library/stdtypes.html#sequence-types-list-tuple-range). They are called *li...
They create different types. ``` >>> type({}) <type 'dict'> >>> type([]) <type 'list'> >>> type({1, 2}) <type 'set'> >>> type({1: 2}) <type 'dict'> >>> type([1, 2]) <type 'list'> ```
22,391,419
what is the difference between curly brace and square bracket in python? ``` A ={1,2} B =[1,2] ``` when I print `A` and `B` on my terminal, they made no difference. Is it real? And sometimes, I noticed some code use `{}` and `[]` to initialize different variables. E.g. `A=[]`, `B={}` Is there any difference ther...
2014/03/13
[ "https://Stackoverflow.com/questions/22391419", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2911587/" ]
Curly braces create [dictionaries](https://docs.python.org/3/library/stdtypes.html#mapping-types-dict) or [sets](https://docs.python.org/3/library/stdtypes.html#set-types-set-frozenset). Square brackets create [lists](https://docs.python.org/3/library/stdtypes.html#sequence-types-list-tuple-range). They are called *li...
These two braces are used for different purposes. If you just want a list to contain some elements and organize them by index numbers (starting from 0), just use the `[]` and add elements as necessary. `{}` are special in that you can give custom id's to values like `a = {"John": 14}`. Now, instead of making a list wit...
22,391,419
what is the difference between curly brace and square bracket in python? ``` A ={1,2} B =[1,2] ``` when I print `A` and `B` on my terminal, they made no difference. Is it real? And sometimes, I noticed some code use `{}` and `[]` to initialize different variables. E.g. `A=[]`, `B={}` Is there any difference ther...
2014/03/13
[ "https://Stackoverflow.com/questions/22391419", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2911587/" ]
They create different types. ``` >>> type({}) <type 'dict'> >>> type([]) <type 'list'> >>> type({1, 2}) <type 'set'> >>> type({1: 2}) <type 'dict'> >>> type([1, 2]) <type 'list'> ```
These two braces are used for different purposes. If you just want a list to contain some elements and organize them by index numbers (starting from 0), just use the `[]` and add elements as necessary. `{}` are special in that you can give custom id's to values like `a = {"John": 14}`. Now, instead of making a list wit...
17,904,216
I've done some searches, but I'm actually not sure of the way to word what I want to take place, so I started a question. I'm sure its been covered before, so my apologies. The code below doesn't work, but hopefully it illustrates what I'm trying to do. ``` sieve[i*2::i] *= ((i-1) / i): ``` I want to take a list an...
2013/07/28
[ "https://Stackoverflow.com/questions/17904216", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2209860/" ]
You can do: ``` >>> def sieve(L, i): ... temp = L[:i] ... for x, y in zip(L[i::2], L[i+1::2]): ... temp.append(x) ... temp.append(y/2) ... return temp ... >>> sieve([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 2) [1, 2, 3, 2, 5, 3, 7, 4, 9, 5] ``` Note that `itself * (2 - 1 ) / 2` is equival...
``` map(lambda x : x * (2 - 1) / 2 if x % 2 == 0 else x, list) ``` This should do what you want it to. **Edit:** Alternately in style, you could use list comprehensions for this as follows: ``` i = 2 list[:i] + [x * (i - 1) / i if x % i == 0 else x for x in list[i:]] ```
17,904,216
I've done some searches, but I'm actually not sure of the way to word what I want to take place, so I started a question. I'm sure its been covered before, so my apologies. The code below doesn't work, but hopefully it illustrates what I'm trying to do. ``` sieve[i*2::i] *= ((i-1) / i): ``` I want to take a list an...
2013/07/28
[ "https://Stackoverflow.com/questions/17904216", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2209860/" ]
[NumPy](http://www.numpy.org/) would actually let you do that! ``` >>> import numpy as np >>> a = np.arange(10) >>> a array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) >>> i = 2 >>> a[i*2::2] *= (i-1.0)/i >>> a array([0, 1, 2, 3, 2, 5, 3, 7, 4, 9]) ``` If you can't use NumPy or prefer not to, a loop would probably be clearest: ...
``` map(lambda x : x * (2 - 1) / 2 if x % 2 == 0 else x, list) ``` This should do what you want it to. **Edit:** Alternately in style, you could use list comprehensions for this as follows: ``` i = 2 list[:i] + [x * (i - 1) / i if x % i == 0 else x for x in list[i:]] ```
17,904,216
I've done some searches, but I'm actually not sure of the way to word what I want to take place, so I started a question. I'm sure its been covered before, so my apologies. The code below doesn't work, but hopefully it illustrates what I'm trying to do. ``` sieve[i*2::i] *= ((i-1) / i): ``` I want to take a list an...
2013/07/28
[ "https://Stackoverflow.com/questions/17904216", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2209860/" ]
You can use Python's [extended slicing](http://docs.python.org/release/2.3.5/whatsnew/section-slices.html) and slice assignment to do that: ``` >>> li=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10] >>> li[3::2]=[x/2 for x in li[3::2]] >>> li [1, 2, 3, 2, 5, 3, 7, 4, 9, 5] ```
``` map(lambda x : x * (2 - 1) / 2 if x % 2 == 0 else x, list) ``` This should do what you want it to. **Edit:** Alternately in style, you could use list comprehensions for this as follows: ``` i = 2 list[:i] + [x * (i - 1) / i if x % i == 0 else x for x in list[i:]] ```
17,904,216
I've done some searches, but I'm actually not sure of the way to word what I want to take place, so I started a question. I'm sure its been covered before, so my apologies. The code below doesn't work, but hopefully it illustrates what I'm trying to do. ``` sieve[i*2::i] *= ((i-1) / i): ``` I want to take a list an...
2013/07/28
[ "https://Stackoverflow.com/questions/17904216", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2209860/" ]
You can do: ``` >>> def sieve(L, i): ... temp = L[:i] ... for x, y in zip(L[i::2], L[i+1::2]): ... temp.append(x) ... temp.append(y/2) ... return temp ... >>> sieve([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 2) [1, 2, 3, 2, 5, 3, 7, 4, 9, 5] ``` Note that `itself * (2 - 1 ) / 2` is equival...
Per your edit, you can do this with a range. ``` for i in range(1, len(listnums), 2): listnums[i] /= 2 ``` If you want to do this with a list comprehension, you can do it similarly to the other version using `enumerate`. ``` def sieve(listnums, divisor): return [num if i % divisor else num/divisor for i, nu...
17,904,216
I've done some searches, but I'm actually not sure of the way to word what I want to take place, so I started a question. I'm sure its been covered before, so my apologies. The code below doesn't work, but hopefully it illustrates what I'm trying to do. ``` sieve[i*2::i] *= ((i-1) / i): ``` I want to take a list an...
2013/07/28
[ "https://Stackoverflow.com/questions/17904216", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2209860/" ]
[NumPy](http://www.numpy.org/) would actually let you do that! ``` >>> import numpy as np >>> a = np.arange(10) >>> a array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) >>> i = 2 >>> a[i*2::2] *= (i-1.0)/i >>> a array([0, 1, 2, 3, 2, 5, 3, 7, 4, 9]) ``` If you can't use NumPy or prefer not to, a loop would probably be clearest: ...
You can do: ``` >>> def sieve(L, i): ... temp = L[:i] ... for x, y in zip(L[i::2], L[i+1::2]): ... temp.append(x) ... temp.append(y/2) ... return temp ... >>> sieve([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 2) [1, 2, 3, 2, 5, 3, 7, 4, 9, 5] ``` Note that `itself * (2 - 1 ) / 2` is equival...
17,904,216
I've done some searches, but I'm actually not sure of the way to word what I want to take place, so I started a question. I'm sure its been covered before, so my apologies. The code below doesn't work, but hopefully it illustrates what I'm trying to do. ``` sieve[i*2::i] *= ((i-1) / i): ``` I want to take a list an...
2013/07/28
[ "https://Stackoverflow.com/questions/17904216", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2209860/" ]
[NumPy](http://www.numpy.org/) would actually let you do that! ``` >>> import numpy as np >>> a = np.arange(10) >>> a array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) >>> i = 2 >>> a[i*2::2] *= (i-1.0)/i >>> a array([0, 1, 2, 3, 2, 5, 3, 7, 4, 9]) ``` If you can't use NumPy or prefer not to, a loop would probably be clearest: ...
Per your edit, you can do this with a range. ``` for i in range(1, len(listnums), 2): listnums[i] /= 2 ``` If you want to do this with a list comprehension, you can do it similarly to the other version using `enumerate`. ``` def sieve(listnums, divisor): return [num if i % divisor else num/divisor for i, nu...
17,904,216
I've done some searches, but I'm actually not sure of the way to word what I want to take place, so I started a question. I'm sure its been covered before, so my apologies. The code below doesn't work, but hopefully it illustrates what I'm trying to do. ``` sieve[i*2::i] *= ((i-1) / i): ``` I want to take a list an...
2013/07/28
[ "https://Stackoverflow.com/questions/17904216", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2209860/" ]
You can use Python's [extended slicing](http://docs.python.org/release/2.3.5/whatsnew/section-slices.html) and slice assignment to do that: ``` >>> li=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10] >>> li[3::2]=[x/2 for x in li[3::2]] >>> li [1, 2, 3, 2, 5, 3, 7, 4, 9, 5] ```
Per your edit, you can do this with a range. ``` for i in range(1, len(listnums), 2): listnums[i] /= 2 ``` If you want to do this with a list comprehension, you can do it similarly to the other version using `enumerate`. ``` def sieve(listnums, divisor): return [num if i % divisor else num/divisor for i, nu...
17,904,216
I've done some searches, but I'm actually not sure of the way to word what I want to take place, so I started a question. I'm sure its been covered before, so my apologies. The code below doesn't work, but hopefully it illustrates what I'm trying to do. ``` sieve[i*2::i] *= ((i-1) / i): ``` I want to take a list an...
2013/07/28
[ "https://Stackoverflow.com/questions/17904216", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2209860/" ]
[NumPy](http://www.numpy.org/) would actually let you do that! ``` >>> import numpy as np >>> a = np.arange(10) >>> a array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) >>> i = 2 >>> a[i*2::2] *= (i-1.0)/i >>> a array([0, 1, 2, 3, 2, 5, 3, 7, 4, 9]) ``` If you can't use NumPy or prefer not to, a loop would probably be clearest: ...
You can use Python's [extended slicing](http://docs.python.org/release/2.3.5/whatsnew/section-slices.html) and slice assignment to do that: ``` >>> li=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10] >>> li[3::2]=[x/2 for x in li[3::2]] >>> li [1, 2, 3, 2, 5, 3, 7, 4, 9, 5] ```
50,567,475
I am upgrading my django application from `Django 1.5` to `Django 1.7`. While upgrading I am getting `django.core.exceptions.AppRegistryNotReady: Models aren't loaded yet` error. I tried with some solution I got by searching. But nothing is worked for me. I think it because of one of my model. Please help me to fix thi...
2018/05/28
[ "https://Stackoverflow.com/questions/50567475", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5939865/" ]
From the traceback I see the following: ``` File "/home/venkat/sample-applications/wfmis-django-upgrade/wfmis-upgrade/django-pursuite/apps/admin/models/__init__.py", line 14, in <module> from occupational_standard import * File "/home/venkat/sample-applications/wfmis-django-upgrade/wfmis-upgrade/django-pursuit...
Stop the venv before upgrading django. Stop the server before upgrading. Update to 1.7 style wsgi handler. Also, use pip to manage & upgrade packages, your script is bound to break the packages otherwise.
11,055,165
From a file, i have taken a line, split the line into 5 columns using `split()`. But i have to write those columns as tab separated values in an output file. Lets say that i have `l[1], l[2], l[3], l[4], l[5]`...a total of 5 entries. How can i achieve this using python? And also, i am not able to write `l[1], l[2], l...
2012/06/15
[ "https://Stackoverflow.com/questions/11055165", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1411416/" ]
The `write()` method takes a string as its first argument (not a variable number of strings). Try this: ``` outf.write(l[1] + l[2] + l[3] + l[4] + l[5]) ``` or better yet: ``` outf.write('\t'.join(l) + '\n') ```
``` outf.write('{0[1]}\t{0[2]}\t{0[3]}\t{0[4]}\t{0[4]}\n'.format(l)) ``` will write the data to the file tab separated. Note that write doesn't automatically append a `\n`, so if you need it you'll have to supply it yourself. Also, it's better to open the file using `with`: ``` with open('output', 'w') as outf: ...
11,055,165
From a file, i have taken a line, split the line into 5 columns using `split()`. But i have to write those columns as tab separated values in an output file. Lets say that i have `l[1], l[2], l[3], l[4], l[5]`...a total of 5 entries. How can i achieve this using python? And also, i am not able to write `l[1], l[2], l...
2012/06/15
[ "https://Stackoverflow.com/questions/11055165", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1411416/" ]
You can use a parameter in the `with` statement representing the file you're writing to. From there, use `.write()`. This assumes that everything in `l` is a string, otherwise you'd have to wrap all of them with `str()`. ``` with open('output', 'w') as f: f.write(l[1] + "\t" + l[2] + "\t" + l[3] + "\t" + l[4] + "\...
The `write()` method takes a string as its first argument (not a variable number of strings). Try this: ``` outf.write(l[1] + l[2] + l[3] + l[4] + l[5]) ``` or better yet: ``` outf.write('\t'.join(l) + '\n') ```
11,055,165
From a file, i have taken a line, split the line into 5 columns using `split()`. But i have to write those columns as tab separated values in an output file. Lets say that i have `l[1], l[2], l[3], l[4], l[5]`...a total of 5 entries. How can i achieve this using python? And also, i am not able to write `l[1], l[2], l...
2012/06/15
[ "https://Stackoverflow.com/questions/11055165", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1411416/" ]
You can use a parameter in the `with` statement representing the file you're writing to. From there, use `.write()`. This assumes that everything in `l` is a string, otherwise you'd have to wrap all of them with `str()`. ``` with open('output', 'w') as f: f.write(l[1] + "\t" + l[2] + "\t" + l[3] + "\t" + l[4] + "\...
``` outf.write('{0[1]}\t{0[2]}\t{0[3]}\t{0[4]}\t{0[4]}\n'.format(l)) ``` will write the data to the file tab separated. Note that write doesn't automatically append a `\n`, so if you need it you'll have to supply it yourself. Also, it's better to open the file using `with`: ``` with open('output', 'w') as outf: ...
56,899,892
I am following along with this pycon video on python packaging. I have a directory: * `mypackage/` + `__init__.py` + `mypackage.py` * `readme.md` * `setup.py` The contents of `mypackage.py`: ``` class MyPackage(): ...
2019/07/05
[ "https://Stackoverflow.com/questions/56899892", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2118666/" ]
First, you usually can find the root cause on **last** `Caused by` statement for debugging. Therefore, according to the error log you posted, `Caused by: org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set` should be key! Although Hibernate is database a...
In my case: 1. I have created **separate new project** with the **same code** and in the **same work-space**. 2. Started the application. 3. This time tomcat started successfully in the first instance itself.
56,899,892
I am following along with this pycon video on python packaging. I have a directory: * `mypackage/` + `__init__.py` + `mypackage.py` * `readme.md` * `setup.py` The contents of `mypackage.py`: ``` class MyPackage(): ...
2019/07/05
[ "https://Stackoverflow.com/questions/56899892", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2118666/" ]
First, you usually can find the root cause on **last** `Caused by` statement for debugging. Therefore, according to the error log you posted, `Caused by: org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set` should be key! Although Hibernate is database a...
1: please create a new project, make it work well, and the tomcat is working well, 2: then copy the codes which you had write with your old project to the new project. 3: is's work very well it's maybe the old workplace with old project is broken, wo can't repair it i hope i can help you!
56,899,892
I am following along with this pycon video on python packaging. I have a directory: * `mypackage/` + `__init__.py` + `mypackage.py` * `readme.md` * `setup.py` The contents of `mypackage.py`: ``` class MyPackage(): ...
2019/07/05
[ "https://Stackoverflow.com/questions/56899892", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2118666/" ]
First, you usually can find the root cause on **last** `Caused by` statement for debugging. Therefore, according to the error log you posted, `Caused by: org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set` should be key! Although Hibernate is database a...
Probably the port that tomcat is starting is busy. Check this. Or simply define another port for your project, edit the ***application.properties*** file with the instruction. Example ``` server.port=9000 ```
56,899,892
I am following along with this pycon video on python packaging. I have a directory: * `mypackage/` + `__init__.py` + `mypackage.py` * `readme.md` * `setup.py` The contents of `mypackage.py`: ``` class MyPackage(): ...
2019/07/05
[ "https://Stackoverflow.com/questions/56899892", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2118666/" ]
First, you usually can find the root cause on **last** `Caused by` statement for debugging. Therefore, according to the error log you posted, `Caused by: org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set` should be key! Although Hibernate is database a...
Resolved it by adding a missing property to application.properties file. spring.jpa.hibernate.ddl-auto=update
56,899,892
I am following along with this pycon video on python packaging. I have a directory: * `mypackage/` + `__init__.py` + `mypackage.py` * `readme.md` * `setup.py` The contents of `mypackage.py`: ``` class MyPackage(): ...
2019/07/05
[ "https://Stackoverflow.com/questions/56899892", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2118666/" ]
Resolved it by adding a missing property to application.properties file. spring.jpa.hibernate.ddl-auto=update
In my case: 1. I have created **separate new project** with the **same code** and in the **same work-space**. 2. Started the application. 3. This time tomcat started successfully in the first instance itself.
56,899,892
I am following along with this pycon video on python packaging. I have a directory: * `mypackage/` + `__init__.py` + `mypackage.py` * `readme.md` * `setup.py` The contents of `mypackage.py`: ``` class MyPackage(): ...
2019/07/05
[ "https://Stackoverflow.com/questions/56899892", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2118666/" ]
Resolved it by adding a missing property to application.properties file. spring.jpa.hibernate.ddl-auto=update
1: please create a new project, make it work well, and the tomcat is working well, 2: then copy the codes which you had write with your old project to the new project. 3: is's work very well it's maybe the old workplace with old project is broken, wo can't repair it i hope i can help you!
56,899,892
I am following along with this pycon video on python packaging. I have a directory: * `mypackage/` + `__init__.py` + `mypackage.py` * `readme.md` * `setup.py` The contents of `mypackage.py`: ``` class MyPackage(): ...
2019/07/05
[ "https://Stackoverflow.com/questions/56899892", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2118666/" ]
Resolved it by adding a missing property to application.properties file. spring.jpa.hibernate.ddl-auto=update
Probably the port that tomcat is starting is busy. Check this. Or simply define another port for your project, edit the ***application.properties*** file with the instruction. Example ``` server.port=9000 ```
8,077,756
in my views.py i obtain 5 dicts, which all are something like {date:value} all 5 dicts have the same length and in my template i want to obtain some urls based on these dicts, with the common field being the date - as you would do in an sql query when joining 5 tables based on a common column in python you would do so...
2011/11/10
[ "https://Stackoverflow.com/questions/8077756", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1023857/" ]
`youredittext.requestFocus()` call it from activity ``` oncreate(); ``` and use the above code there
``` >>you can write your code like if (TextUtils.isEmpty(username)) { editTextUserName.setError("Please enter username"); editTextUserName.requestFocus(); return; } if (TextUtils.isEmpty(password)) { editTextPassword.setError("Enter a password"); ...
8,077,756
in my views.py i obtain 5 dicts, which all are something like {date:value} all 5 dicts have the same length and in my template i want to obtain some urls based on these dicts, with the common field being the date - as you would do in an sql query when joining 5 tables based on a common column in python you would do so...
2011/11/10
[ "https://Stackoverflow.com/questions/8077756", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1023857/" ]
`youredittext.requestFocus()` call it from activity ``` oncreate(); ``` and use the above code there
Set to the Activity in Manifest: ``` android:windowSoftInputMode="adjustResize" ``` Set focus, when a view is ready: ``` fun setFocus(view: View, showKeyboard: Boolean = true){ view.post { if (view.requestFocus() && showKeyboard) activity?.openKeyboard() // call extension function } } `...
8,077,756
in my views.py i obtain 5 dicts, which all are something like {date:value} all 5 dicts have the same length and in my template i want to obtain some urls based on these dicts, with the common field being the date - as you would do in an sql query when joining 5 tables based on a common column in python you would do so...
2011/11/10
[ "https://Stackoverflow.com/questions/8077756", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1023857/" ]
Programatically: ``` edittext.requestFocus(); ``` Through xml: ``` <EditText...> <requestFocus /> </EditText> ``` Or call onClick method manually.
``` >>you can write your code like if (TextUtils.isEmpty(username)) { editTextUserName.setError("Please enter username"); editTextUserName.requestFocus(); return; } if (TextUtils.isEmpty(password)) { editTextPassword.setError("Enter a password"); ...
8,077,756
in my views.py i obtain 5 dicts, which all are something like {date:value} all 5 dicts have the same length and in my template i want to obtain some urls based on these dicts, with the common field being the date - as you would do in an sql query when joining 5 tables based on a common column in python you would do so...
2011/11/10
[ "https://Stackoverflow.com/questions/8077756", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1023857/" ]
Programatically: ``` edittext.requestFocus(); ``` Through xml: ``` <EditText...> <requestFocus /> </EditText> ``` Or call onClick method manually.
having the soft keyboard disabled (only external keyboards enabled), I fixed it by moving the cursors at the end on the EditText: ``` editText.setSelection(editText.getText().length) ```