## [Solved] Print the length of the longest continuous sequence (Python)

Try this instead: sequence = [] stop = False while not stop: num = int(input()) if num == -1: stop = True else: sequence.append(num) longest = 0 length = 0 for i in range(2, len(sequence)): if (sequence[i-2] + sequence[i-1]) == sequence[i]: length += 1 else: longest = max(longest, length) length = 0 First, I read … Read more

## [Solved] Javascript Loop over array of objects and get unique values

Try this let newArray = []; carArray.forEach(function(car) { let arrayKey = Object.keys(car)[0] if (newArray.length > 0) { newArray.find(function (data) { if(!data.hasOwnProperty(Object.keys(data)[0])) { newArray.push(car); } }) } else newArray.push(car) }); 6 solved Javascript Loop over array of objects and get unique values

## [Solved] Is there an alternative to slice in Javascript? [closed]

You could write tokenize which consumes your text input and produces a stream of tokens – const input = [ ‘7’, ‘3’, ‘+’, ‘6’, ‘x’, ‘8’, ‘+’, ‘5’, ‘4’, ‘x’, ‘2’ ] function* tokenize (es) { let r = 0, n for (const e of es) { switch (e) { case “+”: case “x”: yield … Read more

## [Solved] PHP Get 2 data rows in single iteration [closed]

First get all data into an array. Then compose that array multidimensional array. So you can push two rows in every single key something like that. while(\$row = mysql_fetch_assoc(\$query)){ \$data[] = \$row; } \$last_data = array(); \$key = 0; for(\$i=0;\$i<sizeof(\$data);\$i++) { if(\$i%2 == 0) { \$key++; } \$last_data[\$key][] = \$data[\$i]; } Then you can iterate … Read more

## [Solved] Input numeric text for # loops [closed]

Your \$digit variable is the maximum, use it that way. Change your for loop in this for (\$x= 1; \$x <= \$digit; \$x++) { echo ‘Hello ‘ . \$x. ‘<br />’; } Then you will get what you want. solved Input numeric text for # loops [closed]

## [Solved] for loop – why does this print 12 and not 3?

The values of your variables throughout the loops are like follows: x y result ———- 0 0 1 0 1 2 0 2 3 1 0 4 1 1 5 1 2 6 2 0 7 2 1 8 2 2 9 3 0 10 3 1 11 3 2 12 So that’s why result … Read more

## [Solved] How do I iterate through a list to print each variable in the list? [closed]

From your description, I think you want something like this: >>> a = 1 >>> b = 2 >>> c = [3, 4, 5] >>> d = [6, 7, 8] >>> for cx, dx in zip(c, d): for item in (a, b, cx, dx): print(item) print(“—“) 1 2 3 6 — 1 2 4 7 … Read more

## [Solved] Iterate over list

You need to break up the rows and convert each value to an integer. At the moment you are looking for the presence of the string “3” which is why strings like “2;13” pass the test. Try something like this: list_6 = [“4;99”, “3;4;8;9;14;18”, “2;3;8;12;18”, “2;3;11;18”, “2;3;8;18”, “2;3;4;5;6;7;8;9;11;12;15;16;17;18”, “2;3;4;8;9;10;11;13;18”, “1;3;4;5;6;7;13;16;17”, “2;3;4;5;6;7;8;9;11;12;14;15;18”, “3;11;18”, “2;3;5;8;9;11;12;13;15;16;17;18”, “2;5;11;18”, “1;2;3;4;5;8;9;11;17;18”, … Read more

## [Solved] Python Error with iteration, for loop

Please look at the formatting tips, it will help you display your code as you wish. that said, I think this is what you want. The following code will iterate through each character in your list string. If it finds a match, it will print success list = “9876554321” for char in list: if char … Read more

## [Solved] What is the use of iter in python?

First of all: iter() normally is a function. Your code masks the function by using a local variable with the same name. You can do this with any built-in Python object. In other words, you are not using the iter() function here. You are using a for loop variable that happens to use the same … Read more