Arrays
Data Types
def return_numbers(list): return [int(i) for i in list if str(i).isnumeric()]
public class myWorld{public static void printArray(int[] arr){for(int i : arr)System.out.println(i);}}- def return_numbers(list):
- return [int(i) for i in list if str(i).isnumeric()]
test.assert_equals(return_numbers([1,2,'a',3,'b']), [1,2,3]) test.assert_equals(return_numbers(['1500','12h','0b100','hello',' ', 1232]), [1500, 1232])
import org.junit.Test;import static org.junit.Assert.assertEquals;import org.junit.runners.JUnit4;public class SolutionTest {@Testpublic void test(){myWorld.printArray(new int[]{3,2,1,4,5});}}- test.assert_equals(return_numbers([1,2,'a',3,'b']), [1,2,3])
- test.assert_equals(return_numbers(['1500','12h','0b100','hello',' ', 1232]), [1500, 1232])
Takes a string of an even length, splits it in two and intertwines those to generate the output string.
e.g intertwine('135246') --> '123456'
intertwine('11223344') --> '13132424'
def intertwine(text):
return ''.join([val+'' for pair in zip(text[:len(text)//2], text[len(text)//2:]) for val in pair])
Test.describe("Basic tests")
Test.assert_equals(intertwine('135246'), '123456')
Test.assert_equals(intertwine('11223344'), '13132424')
Test.assert_equals(intertwine('abracadabra!'),'adbarbarcaa!')