Python examples to to check the end of a string for specific text patterns e.g. domain name extenstions and so on. Use endswith() with strings A simple way to check the end a string is to use the String.endswith(). Use endswith() with tuples If you need to check against multiple choices, simply provide a tuple […]
Python examples to to check the start of a string for specific text patterns e.g. URL schemes and so on. Use startswith() with strings A simple way to check the beginning a string is to use the String.startswith(). Use startswith() with tuples If you need to check against multiple choices, simply provide a tuple of […]
Python example to split string into fields using the delimiters in the string. Split string using split() method Easiest way to split a string using a delimiter is using string.split( delimiter ) function. Split string with multiple delimiters The split() method of string objects is really meant for very simple cases, and does not allow […]
Python example to find common items between 2 or more dictionaries i.e. dictionary intersection items. Find common items using ‘&’ operator Simplest method is to use & operator between dictionaries. Use set.intersection() method Happy Learning !!
An OrderedDict maintains the insertion order of items added to dictionary. The order of items is preserved when iterating or serializing also. OrderedDict example To easily construct such dictionaries, you can use defaultdict in the collections module. A feature of defaultdict is that it automatically initializes the first value so you can simply focus on […]