[Tutor] Help regarding creating tags

Alan Gauld alan.gauld at yahoo.co.uk
Wed Nov 1 06:52:38 EDT 2017


On 01/11/17 06:02, Hemant Sain wrote:
> i want to tag categories to its menuname.

Your description below does not explain how you will
tag them together, you simply identify which menu
items have a category, but no way to determine
which category goes with which menu item?

> i have a csv containing menu item name and in other 
> csv i have a column containing some strings,

> i want to pick that strings from categories and look into  menu items if
> any menu item containing that string i want to create a new column next to
> menu item name flagged as 1 otherwise 0
> and the only condition is once a menu item flagged
> as 1 i don't need to consider that menu item again
> to tag further in case of redundant strings

That sounds like what you think the solution
should be rather than your actual requirement.
I'd suggest it might be easier to create two
lists and move the found results into the
second list. this has the advantage of reducing
the number of items to be searched without having
to do any extra tests

But at the end you will simply have identified
which items have a category and which have not,
you will not have identified which category
each item belongs to. Maybe you need to store
the category alongside the items once you find
a match? Or better still use a dictionary keyed
by category?

In pseudo code it might look like:

results = {}
for category in categories:
    results[category] = [ item for item in menuitems
                          if category in item ]

But maybe a dictionary is not what you need
for your output format? And what to do with
menuitems that don't match any category?
That take us back to a dual list approach.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos




More information about the Tutor mailing list