Question

How to copy the values of an array to another one that has a larger length...

How to copy the values of an array to another one that has a larger length , without effecting it.

For example:

A = stdarray.create1D(5)

A = [ 1,2,3,4,5]

B = stdarray.create1D(10)

B = [none, none, none, none, none, none, none , none, none, none]

I want B to have A values..

B = [ 1,2,3,4,5, none, none, none, none, none]

IN PYTHON, without using append.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

A = [1,2,3,4,5]
B = [None,None,None,None,None,None,None,None,None,None]
print(A)
print(B)
#now copying A to B, with out effecting any values
for i in A:
#finding value with None to place
for j in range(len(B)):
if B[j]==None:
B[j]=i
break
print(B)

Add a comment
Know the answer?
Add Answer to:
How to copy the values of an array to another one that has a larger length...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Q1) How would you declare an array of doubles called myDoubles? Arrays can be initialized in...

    Q1) How would you declare an array of doubles called myDoubles? Arrays can be initialized in one of two ways. In one method, the array elements are placed in a list enclosed in curly braces after the array name definition. For example, the code below creates an array of ints with 3 elements: 1, 2 and 3. int[] a = {1, 2, 3, 4}; We can also initialize an array with a new construct, indicating how many elements we want...

  • C++. Write a program that copies the contents of one array into another array but in...

    C++. Write a program that copies the contents of one array into another array but in reverse order using pointers.           - in main()                    - define 2 arrays of type int, 10 elements each                              - initialize one array with numbers 1 through 10                              - initialize all elements of the second array to 0                    - call function reverseCopy with both arrays as arguments                    - display the values of array number 2 (reversed order)           - reverseCopy...

  • (C++ program )Write a function that accepts an int array and the array’s size as arguments. The function should create a new array that is one element larger than the argument array. The first element...

    (C++ program )Write a function that accepts an int array and the array’s size as arguments. The function should create a new array that is one element larger than the argument array. The first element of the new array should be set to 0. Element 0 of the argument array should be copied to the element 1 of the new array. Element 1 of the argument array should be copied to element 2 of the new array, and so forth....

  • In Python, How to return a copy of the list, return the max value in the...

    In Python, How to return a copy of the list, return the max value in the list, flatten the list of lists to have only one level, e.g. >>> flatten([[1, 2], [3, 4], [5, 6]]) >>> [1, 2, 3, 4, 5, 6] I want to solve the problem without a list comprehension and with a list comprehension to see the difference with comments to be able to understand it

  • C++ Code Pass By Reference Practice Write the following functions for basic array operations based on...

    C++ Code Pass By Reference Practice Write the following functions for basic array operations based on the function descriptions given below. Write the following functions for basic array operations based on the function descriptions given below. FindMinArray: This function will search an array of integers (passed to the function as a parameter) for its minimum value, then return that value. SumArray: This function will sum an array of integers (passed to the function through a parameter) then return that sum....

  • In C++ language, implement a class that can sort an array of numbers using all three...

    In C++ language, implement a class that can sort an array of numbers using all three algorithms we have seen in this course, but each method updates a “counter” value every time it accesses the array. Have it print this at the end of the sorting process. Store the array values in an “original” array so you don’t have to re-type it for different sorts (since each sort alters the array), and have the sort modify a copy. Note: IF...

  • In C++ language, implement a class that can sort an array of numbers using all three...

    In C++ language, implement a class that can sort an array of numbers using all three algorithms we have seen in this course, but each method updates a “counter” value every time it accesses the array. Have it print this at the end of the sorting process. Store the array values in an “original” array so you don’t have to re-type it for different sorts (since each sort alters the array), and have the sort modify a copy. Note: IF...

  • Write a complete Java program which has two methods, one to enter values for an array...

    Write a complete Java program which has two methods, one to enter values for an array and another one to sort it using Bubble Sort method. Draw DIAGRAMS for memory allocation, AR and ARI for the program.

  • In python, PART A: I am trying to get a dictionary with size(4, 5, 6) as...

    In python, PART A: I am trying to get a dictionary with size(4, 5, 6) as keys and an array for key containing a list of values (words from file of respective size) associated with those keys I am reading from a file of strings, where I am only interested with words of length 4, 5, and 6 to compute my program reading the text file line by line: At first, I have an empty dictionary then to that I...

  • If the length of the array P is 4 and the length of the array T...

    If the length of the array P is 4 and the length of the array T is 14, how many shifts of P need to be performed in the string searching algorithm? a. 9 b. 10 c. 11 d. 12 What is the best case for the naive string search algorithm? a. The first character of the pattern P isn't present in text T b. All characters in pattern P are different c. All characters in text T are different...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT