integer

Converting each line from a list of integers into an array of integers?

我的未来我决定 提交于 2020-12-15 06:13:51
问题 I'm new to Java, so apologies if any of this is unclear - I want to convert a list of four-digit integers into a list of integer arrays - i.e if I have an integer that is 4567, I want to convert that into an array of four separate integers [4, 5, 6, 7]. So I want to convert each line/index of the list into it's own array (rather than converting the entire list into an array). I'm currently reading a file that has four-digit integers (each on a new line) and adding them to a list, which is

Converting each line from a list of integers into an array of integers?

随声附和 提交于 2020-12-15 06:12:02
问题 I'm new to Java, so apologies if any of this is unclear - I want to convert a list of four-digit integers into a list of integer arrays - i.e if I have an integer that is 4567, I want to convert that into an array of four separate integers [4, 5, 6, 7]. So I want to convert each line/index of the list into it's own array (rather than converting the entire list into an array). I'm currently reading a file that has four-digit integers (each on a new line) and adding them to a list, which is

Program to work out an age gives error about a getset_descriptor?

我的未来我决定 提交于 2020-12-12 05:08:45
问题 I am trying to write a very simple Python program to work out someone's age and I think, in theory, it should work however every time I try to run it, it throws this error: What year were you born in? 2005 Traceback (most recent call last): File "python", line 5, in <module> TypeError: unsupported operand type(s) for -: 'getset_descriptor' and 'int' I have tried turning datetime.year and (year) (same things) in to integers. It worked but didn't make a difference as the both are already

Program to work out an age gives error about a getset_descriptor?

梦想的初衷 提交于 2020-12-12 05:08:14
问题 I am trying to write a very simple Python program to work out someone's age and I think, in theory, it should work however every time I try to run it, it throws this error: What year were you born in? 2005 Traceback (most recent call last): File "python", line 5, in <module> TypeError: unsupported operand type(s) for -: 'getset_descriptor' and 'int' I have tried turning datetime.year and (year) (same things) in to integers. It worked but didn't make a difference as the both are already

Is pointer just an integer?

落爺英雄遲暮 提交于 2020-12-09 05:09:32
问题 If I know the address of an data object, could I store the address as an integer and operate the integer as a pointer? For example, void main(){ long a = 101010; long *p = &a; long b = p; printf("%lld\n", *(long*)b); } Is it always safe? Comments: long b = p; produces a warning: Initialization makes integer from pointer without a cast However, the program prints 101010 . 回答1: It's not guaranteed by the standard that such cast would always work. To store a pointer in an integral type, use

How to split integer input in python?

血红的双手。 提交于 2020-11-29 23:49:59
问题 If you write like n = str(input()) n = n.split() print(n) That will work. But if you try to do it with integers, you will get `Value Error`. How to do it with int type? 回答1: Do you want to separate several numbers? 1 2 3 -> [1, 2, 3] n = str(input()) n = n.split() numbers = [int(i) for i in n] print(numbers) Or split a number in numeral? 123 -> [1, 2, 3] n = str(input()) numbers = [int(i) for i in n] print(numbers) Use Nikhil answer, if you want to split a number with delimiters 1%3 -> [1, 3]

regex for only numbers in string?

北城以北 提交于 2020-11-29 08:25:45
问题 I can't find the regex for strings containing only whitespaces or integers. The string is an input from user on keyboard. It can contain everything but \n (but it doesn't matter I guess), but we can focus on ASCII since it's supposed to be English sentences Here are some examples: OK: '1' '2 3' ' 3 56 ' '8888888 333' ' 039' not OK: 'a' '4 e' '874 1231 88 qqqq 99' ' shf ie sh f 8' I have this which finds the numbers: t = [int(i) for i in re.findall(r'\b\d+\b', text)] But I can't get the regex.

regex for only numbers in string?

谁说我不能喝 提交于 2020-11-29 08:25:43
问题 I can't find the regex for strings containing only whitespaces or integers. The string is an input from user on keyboard. It can contain everything but \n (but it doesn't matter I guess), but we can focus on ASCII since it's supposed to be English sentences Here are some examples: OK: '1' '2 3' ' 3 56 ' '8888888 333' ' 039' not OK: 'a' '4 e' '874 1231 88 qqqq 99' ' shf ie sh f 8' I have this which finds the numbers: t = [int(i) for i in re.findall(r'\b\d+\b', text)] But I can't get the regex.