11 ms·
Python: "<br>".join(["string1","string2"]) Maybe it shouldn't but this pisses me off.
by twism 18y ago
Python: "<br>".join(["string1","string2"])
Maybe it shouldn't but this pisses me off.
- apu 18y agoWhat don't you like about this?
- twism 18y agoThe fact 'join' being a method of a string that accepts an array as an argument. I guess it isn't that bad, I just think I've been conditioned to expect it the other way around.
- Zaak 18y agostr.join("<br>", ["string1", "string2"]) I hate it too.
- eru 18y agoI like it.
- rbanffy 18y agoI would think a more natural approach of making join a method of any sequence would result in cleaner programs. (a, b, c).join(',') instead of: ','.join((a, b, c))
- cabalamat 18y agoI agree. Join should word the same as split: >>> "abcbe".split("b") ['a', 'c', 'e'] So to get back the original string you should be able to say: ['a', 'c', 'e'].join("b") #!!! WRONG !!! but this doesn't work and instead you have to say: >>> "b".join(['a', 'c', 'e']) 'abcbe'
- zepolen 18y agoYou miss out on a nice side-effect of join being a method of string: br = '<br>'.join br((a, b, c)) Personally I think it makes more sense the ruby way but it's never bugged me.
- rbanffy 18y agoWow... This one is quite pretty. Really. A very nice side effect of the "everything is an object" concept.
- silentbicycle 18y agoThere's not any reason you need objects for that, though. Python's join in the string module is called as join(list [,sep])*, and you could say def br(sl): return string.join(sl, "<br>") or br = lambda sl: string.join(sl, "<br>") for the same effect. It's actually due to first-class functions.
- Erwin 18y agoMy string/sequence related annoyince is ''.split() -vs- ''.split(';'). The first returns [], but the second returns [''].