Essential Python Programming Snippets and Algorithms
Classified in Computers
Written on in
English with a size of 3.17 KB
Jabber JID to Email Conversion
def jid2email(jid):
email = jid[:jid.find('/')]
return email
if __name__ == '__main__':
jabber = '[email protected]/quertyy'
print(jid2email(jabber))Lists vs. Tuples
Lists are mutable and can be changed by internal operations, whereas tuples are immutable.
Remove Duplicates from String
def remove_dup(string):
result = []
for char in string:
if char not in result:
result.append(char)
return ''.join(result)Identical Character Count
def count_max(in_string):
d = dict()
for c in in_string:
d[c] = d.get(c, 0) + 1
return max(d.items(), key=lambda x: x[1])
# Using collections
from collections import Counter
def counter_max(in_string):
return Counter(in_... Continue reading "Essential Python Programming Snippets and Algorithms" »