0

I have 1 bitsInfo string:

bitsInfo="0100001111110001"

and 1 array bitReplace which includes subarray:

bitReplace=[["1","5","00000"],["8","11","0000"]]

The first element of the subarray is startbit location and the second element is the endbit location.

The goal of the script is to replace the bitsInfo string (with the third element of subarray) base on startbit and endbit information.

The expected result should be

bitsFinal="0000001100000001"

I have tried this method:

for bits in bitReplace:
    bitsFinal = bits[:int(bits[0])+bits[2]+ bits[int(bits[1]+1:]

This method doesn't really work. May I know what went wrong?

2 Answers 2

1

You are close but you are not using the original string anywhere. Try this:

bitsFinal = bitsInfo
for bits in bitReplace:
     bitsFinal = bitsFinal[:int(bits[0])] + bits[2] + bitsFinal[int(bits[1])+1:]

the result is:

>>> bitsFinal
'0000001100000001'
Sign up to request clarification or add additional context in comments.

Comments

0
for bits in bitReplace:
  bitsFinal = bits[:int(bits[0])]+bits[2]+ bits[int(bits[1])+1:]

I think there are problems with parantheses.

2 Comments

Not a complete answer.
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.