Re: [Tutor] Help regarding creating tags
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 ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Help regarding creating tags
i want to tag categories to its menuname. 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 in categories only i want to search which are flagged as 0. please help me with the python script. *Menu Name* 9\ bobbie" 9\ chz steak" 9\ tuna" provolone 20\ bobbie" bottled soda 20oz cran-slam ww american small chips medium drink 9\ meatball" capriotti's water 20'' chicken cheese steak 9\ veg turkey" medium chips 9\ capastrami" 12\ bobbie" 12'' chicken cheese steak cookie 12\ chz steak" 9\ cole turkey" kid grilled cheese white 12\ italian" 12\ meatball" 12\ capastrami" turkey sand w 20\ slaw be jo" swiss 12\ cole turkey" large drink 9\ ham" 9'' chicken cheese steak 9\ slaw be jo" turkey sand ww stuffing 12\ turkey" 9\ italian" 12\ slaw be jo" 9\ grld italian" 12\ veg burger w/chz" extra american black salad 9\ turkey" 20\ turkey" 20\ capastrami" ham sand w 12\ mushroom" 12\ grld italia" italian salad tuna sand ww 9\ roast beef" 20\ chz steak" 20\ mushroom" 9\ veg chzstk" ham genoa 12\ veg turkey" 12\ veggie cole turkey" 9\ mushroom" cap's creation mushrooms salad chicken 20\ cole turkey" 1 pack chicken kr veg burger w/chz 12\ roast beef" kid turkey n cheese white 20\ italian" 12\ ham" 9\ employee sub" roast beef kr 9\ veggie cole turkey" 12\ sausage" tea turkey sand kr salad turkey tuna sand kr brownie slice american cheese 1 oz pastrami 9\ cheese" 12\ italian up" 12\ capastrami up" 1 pack steak delaware's finest small the sampler sm side ranch dressing 12\ veg turkey up" 20\ roast beef" roast beef w 1oz turkey 12\ tuna" 20\ veg turkey" 12\ veg chzstk" 9\ sausage" kid ham n cheese white side italian dressing salad provolone 20\ grld italia" sample item 6 sample item 9 turkey 12\ slaw be jo up" 12\ meatball up" 1 oz roast beef ham sand ww delaware's finest large side cole slaw large large chips 20\ meatball" 12'' chick cheese stk up 12\ chz steak up" 12\ grld italia up" cran-slam w 12\ bobbie up" 20\ cheese" slice provolone the sampler lg meatball bar slice ham wise large chips small side sm soup 12\ tuna up" 12\ cole turkey up" prosciutini 20\ veggie cole turkey" soup roast beef 20\ italian up" 20'' chick cheese stk up 20\ chz steak up" 20\ bobbie up" 20\ veg turkey up" slice swiss 20\ capastrami up" sample item 7 12\ ham up" salad swiss 12\ veggie cheese stk up" california omelet orange juice exteme bac boy dinner salad chef salad 12\ turkey up" the big cheese combo it fries cmb sm pepsi km cheese burger #NAME? #NAME? kid grilled cheese wheat kids ham cheese white box calif. blt bacon turkey melt coffee 1-pc pancake fries tuna sand biscuits & gravy s-1/3 patty x avocado x chez s-bacon #NAME? xtra egg lg bev upcharge sm ice tea small soup roast beef ww salad tuna med pepsi 20\ veg chzstk up" day nm egg san s-chkn brest bell pepper fruit 1 slice veggie turkey s-toast x sausage 1 pack sausage chicken salad lg pepsi x dressing large side 9\ firecracker turkey" 20\ sausage up" 20\ turkey up" 20\ veg chzstk" lg ice tea 12\ roast beef up" sample item 8 catering cap creation sal the turkey lover sm little italy sm cookie tray sd chk avo san sm fry / 2 pc zucch kid turkey n cheese wheat junior chz burger extra italian meat chili chz fries sm fry / 2 pc o ring extra turkey *CATEGORIES* non-veg chix salmon ch chkn brisket brskt bacon bcn chse mahi dog shk clam parmesan asiago prosciutto prosciutti salami Angus hicken chk chick wings prk pork ham bacon ribs fish shrimp tuna beef steak stk meatball non-veg chix salmon ch chkn brisket brskt bacon bcn chse mahi dog shk clam parmesan asiago prosciutto prosciutti salami Angus hicken chk chick wings prk pork ham bacon ribs fish shrimp tuna beef steak stk meatball i want to tag categories to its menuname. i have a csv containing menu item name and in other csv i have a colunmn 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 dont need to consider that menu item again to tag further in case of redudant strings in categories only i want to search which are flagged as 0. please help me with the r script. Menu Name 9\ bobbie" 9\ chz steak" 9\ tuna" provolone 20\ bobbie" bottled soda 20oz cran-slam ww american small chips medium drink 9\ meatball" capriotti's water 20'' chicken cheese steak 9\ veg turkey" medium chips 9\ capastrami" 12\ bobbie" 12'' chicken cheese steak cookie 12\ chz steak" 9\ cole turkey" kid grilled cheese white 12\