Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

remove commas , and [ ] from a list python 3

I have a this funtion

n=5
nums=5 1 4 2 3

def LIS(nums, n):
    dp = [] 
    dp_list = [] 

    for i in range(n):
        dp.append(1)
        dp_list.append([nums[i]])
        for j in range(i):
            if nums[j] < nums[i]:
                dp[i] = max(dp[i], dp[j] + 1)
                if len(dp_list[i]) <= len(dp_list[j]):
                    dp_list[i] = dp_list[j] + [nums[i]]
   
    print(dp_list[dp.index(max(dp))])
    return dp_list

And I get this result:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

[1, 2, 3]

But I wan something like this as result

1 2 3

I have tried using this, but the result still been the same

values = ''.join([str(i) for i in LIS(nums,n)])

>Solution :

print(*dp_list[dp.index(max(dp))])
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading