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

Print List elements in loop without Brackets and Quote marks

I am trying to print the elements of a list inside a loop but the elements are displaying surrounded by [”]. Is there any way to format output to remove these. Further code and examples shown below

This is the code i am running:

        for i in range(len(get_recipe_titles)): 
            if i ==0:
                j = get_recipe_titles[i]; 
                Title = recipedf[recipedf['id'] == j] 
                Title = Title['title'].values 
                print('Recipe Recommendations for: {0}'.format(Title[0]))
            else: 
                j = get_recipe_titles[i];
                Title = recipedf[recipedf['id'] == j]
                Title = Title['title'].values
                Distance =dist.flatten()[i]
                i = i+1
                print(Title, "With Distance of ", Distance)`

The output is this. I want the [”] removed from the titles of the recepies:

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

Recipe Recommendations for: Three-tier red velvet cake

['Daffodil biscuits'] With Distance of 2.23606797749979

['Belgian waffles'] With Distance of 2.449489742783178

['Easy brownies'] With Distance of 2.6457513110645907

['Red velvet cake'] With Distance of 2.6457513110645907

["Cheat's waffles"] With Distance of 2.6457513110645907

['Scary Halloween cookies'] With Distance of 2.6457513110645907

['Chocolate chip muffins'] With Distance of 2.8284271247461903

['Bundt cake'] With Distance of 2.8284271247461903

['Chocolate beetroot cakes'] With Distance of 2.8284271247461903

I have used .format() in the code above to print the title on the first line of the output without Brackets and Quotes but cant seem to use it for the rest of the output. Is there any way to remove them or is there anywhere i am going wrong

>Solution :

You probably just need to access the zero’th element of the numpy array Title like you did in the first part of the code.

See you did this in the first part:

print('Recipe Recommendations for: {0}'.format(Title[0]))

so do this in the second part:

print(Title[0], "With Distance of ", Distance)
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