Issue
class Solution:
def buildArray(self, nums):
ans=[]
for i in range(len(nums)):
ans.append(nums[nums[i]])
return ans
sol = Solution()
res = sol.buildArray([0,2,1,5,3,4])
print(res)
output:
[0, 1, 2, 4, 5, 3]
The problem is in the output , iam sturggling to remove space after comma ',' in the list . Can any body help me with this one
Solution
You need to turn the list into a string first, which will make that kind of manipulation easier.
Try replacing your last line for this:
res_str = str(res).replace(", ", ',')
print(res_str)
Answered By - Johannes Answer Checked By - Candace Johnson (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.