numbers

I want to extract a certain number of words surrounding a given word in a long string(paragraph) in Python 2.7

心已入冬 提交于 2019-12-24 10:14:03
问题 I am trying to extract a selected number of words surrounding a given word. I will give example to make it clear: string = "Education shall be directed to the full development of the human personality and to the strengthening of respect for human rights and fundamental freedoms." 1) The selected word is development and I need to get the 6 words surrounding it, and get : [to, the, full, of, the, human] 2) But if the selected word is in the beginning or in second position I still need to get 6

Calculate logarithm by hand

一笑奈何 提交于 2019-12-24 09:55:11
问题 I'd like to calculate the mathematical logarithm "by hand"... ... where stands for the logarithmBase and stands for the value. Some examples (See Log calculator): The base 2 logarithm of 10 is 3.3219280949 The base 5 logarithm of 15 is 1.6826061945 ... Hoever - I do not want to use a already implemented function call like Math.ceil, Math.log, Math.abs, ... , because I want a clean native solution that just deals with +-*/ and some loops. This is the code I got so far: function myLog(base, x)

Regular expression extracting number dimension

落爺英雄遲暮 提交于 2019-12-24 09:29:46
问题 I'm using python regular expressions to extract dimensional information from a database. The entries in that column look like this: 23 cm 43 1/2 cm 20cm 15 cm x 30 cm What I need from this is only the width of the entry (so for the entries with an 'x', only the first number), but as you can see the values are all over the place. From what I understood in the documentation, you can access the groups in a match using their position, so I was thinking I could determine the type of the entry

iOS DDMathParser Get Number 'Blocks'

可紊 提交于 2019-12-24 08:55:24
问题 I am building a calculator app for iOS using DDMathParser. I would like to know how to separate an expression ( NSString ) like 5+900/32 into its individual number values: 5 , 900 , and 32 . I would prefer that I get these in an NSArray or other relatively useful list object. I have heard that there is an easy way to do this with DDMathParser - It's why I switched from GCMathParser . 回答1: DDMathParser author here. Yes, this is very easy, and there are a couple of ways to go about it. If you

determine if a string is a number with NSScanner

夙愿已清 提交于 2019-12-24 08:48:14
问题 i'm trying to find out if my string contains any floatValue, and resign the first responder if it's the case, if it's not, the textfield keyboard should stay on screen. This code always hides the keyboard, even if it's not a floatValue : do you know how to make it work? - (BOOL)textFieldShouldReturn:(UITextField *)textField { NSScanner *scan = [NSScanner scannerWithString:[textField text]]; if ([scan scanFloat:NULL]){ [password resignFirstResponder]; [passwordLength resignFirstResponder];

Finding the # of sequences in an array

跟風遠走 提交于 2019-12-24 08:39:32
问题 I need to report the # of sequences in an array. For example: A=[ 1 1 -1 -1 -1 -1 -1 0 1 -1 -1 -1 -1 1 1 -1 -1 1 0 1 1] and I have to report the # of times a number comes consecutively, such as, one sequence of 5 -1s ([-1 -1 -1 -1 -1]) and one sequence of 4 -1s ([-1 -1 -1 -1]) . How can I find how many sequences of numbers there are? 回答1: You may use run-length encoding to perform this task function [rl data] = runLength( vec ) % run length encoding for vector vec rl = ( find( vec ~= [vec(2

XSL formatting number with 'hyphens' every two digits

元气小坏坏 提交于 2019-12-24 07:06:05
问题 I have searched for days and found one example [here][1] [1]: XSLT formatting numbers, insert '-' after every 4 digits starting from the right most digit, but it doesn't seem to work out as expected. Here is what I need to happen. I have a number that is 7 digits like '1122334' and I need to coerce it to '11-22-33-4'. Here is my code so far: <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="xml"/> <xsl:template match="/dataset"> <xsl:decimal

Print numbers in terms of engineering units in Python [duplicate]

爱⌒轻易说出口 提交于 2019-12-24 07:03:23
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Print number in engineering format How do I print numbers in scientific notation with powers that are multiples of 3? For example: 1.5e4 --> 15e3 1.27e-8 --> 12.7e-9 2.9855e-11 --> 29.855e-9 I'm looking for a function similar to the ENG button on a calculator. Is there a Python package somewhere that does this? 回答1: It appears there isn't such a feature yet (at least in Python 2.7), see: http://bugs.python.org

Checking if a given date hour is within a predefined interval with datenum()

不打扰是莪最后的温柔 提交于 2019-12-24 06:46:28
问题 I have a table with dates (and other things), which I have extracted from a CSV file. In order to do some processing of my data (including plotting) I decided to convert all my date-strings to date-numbers (below for simplicity reasons I will exclude all the rest of the data and concentrate on the dates only so don't mind the step from dates to timetable and the fact that it can be omitted): dates = [7.330249777777778e+05;7.330249291666667e+05;7.330246729166667;7.330245256944444;7

Rounding number to two decimal places

社会主义新天地 提交于 2019-12-24 06:45:00
问题 Hy guys, I have a case where a want to round the number to exactly two decimal places. I will give an example and what I tried. Lets say I have 15.07567 To round it up I did: price = Math.round(15.07567 * 100) / 100; // and I get 15.08 But this presents a problems if we have digits that end wit 0 (example 15.10) and we want two decimals. price = Math.round(15.10 * 100) / 100; //15.1 Hmmm, so I tried to use toFixed() price = Math.round(15.10 * 100) / 100; total = price.toFixed(2); // I get "15