count_in_array(A,x)
that
that takes an array A of numbers and a number x,
and returns the number of times the value x appears
in A.
Examples and testing: Test your solution using the
interactive Python interpreter. If you call
count_in_array(5, [7, 5, 16, 3, 10, 5, 8, 1, 29, 13, 28])
, the result
should be 2
.
For example, with this input:
7 3 -2 10 5 -3 3 5 8The output must be as follows:
# # # # # # # # # # # ## ## # ## ## ## ## ### ## ## ### ## ## ### --------- # # # # #
partition_even_odd
that takes an array of
integers, and that changes that array in-place so that
all the even elements precede all the odd
elements. The change is in-place in the sense that it
must be carried out just by swapping elements of the input array,
in particualar without creating other arrays.
Also write a python program to test
the partition_even_odd
function. The program must
compile an array by reading a sequence of integers from the
standard input, with one or more numbers per line, then
call partition_even_odd
, and then print the content
of the array on the standard output. For example, with this input
7 3 2 10 5 3 3 5 8The output might be this:
2 10 8 7 3 5 3 3 5but never this:
8 3 2 10 5 3 3 5 7