Arrays
def return_numbers(list): return [int(i) for i in list if str(i).isnumeric()]
1 − public class myWorld{
2 − public static void printArray(int[] arr){
3 − for(int i : arr)
4 − System.out.println(i);
5 − }
6 − }
1 + def return_numbers(list):
2 + return [int(i) for i in list if str(i).isnumeric()]
3 +
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])
1 − import org.junit.Test;
2 − import static org.junit.Assert.assertEquals;
3 − import org.junit.runners.JUnit4;
4 − 5 − public class SolutionTest {
6 − 7 − @Test
8 − public void test(){
9 − myWorld.printArray(new int[]{3,2,1,4,5});
10 − }
11 − }
1 + test.assert_equals(return_numbers([1,2,'a',3,'b']), [1,2,3])
2 + 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!')