Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to subtract two strings?

I have a long string, which is basically a list like str="lamp, bag, mirror," (and other items)

I was wondering if I can add or subtract some items, in other programming languages I can easily do: str=str-"bag," and get str="lamp, mirror," this doesnt work in python (I'm using 2.7 on a W8 pc)

Is there a way to split the string across say "bag," and somehow use that as a subtraction? Then I still need to figure out how to add.

like image 805
max smith Avatar asked Sep 06 '25 13:09

max smith


1 Answers

you could also just do

print "lamp, bag, mirror".replace("bag,","")
like image 91
Joran Beasley Avatar answered Sep 09 '25 05:09

Joran Beasley