This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Reverse String""" | |
words = "python is awesome !!" | |
reverse_string_1 = words[::-1] | |
"""First way""" | |
# !! emosewa si nohtyp | |
"""Second way""" | |
reverse_string_2 = ''.join(reversed(words)) | |
# !! emosewa si nohtyp |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import Counter | |
"""Check if two words are anagram""" | |
a = "listen" | |
b = "silent" | |
is_anagram = Counter(a) == Counter(b) | |
# True |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import Counter | |
"""Find most frequent in list""" | |
arr = [1, 2, 3, 1, 2, 4, 6, 7, 3, 2, 3, 4] | |
cnt = Counter(arr) | |
# Counter({2: 3, 3: 3, 1: 2, 4: 2, 6: 1, 7: 1}) | |
"""Show only frequent in 2 times""" | |
print(cnt.most_common(2)) | |
# [(2, 3), (3, 3)] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Swapping Variable""" | |
a, b = 10, True | |
print(f'before swapping value a = {a}, b = {b}') | |
# before swapping value a = 10, b = True | |
a, b = b, a | |
print(f'after swapping value a = {a}, b = {b}') | |
# after swapping value a = True, b = 10 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Simple Variable""" | |
a = 10 | |
print(f'simple variable a = {a}') | |
# simple variable a = 10 | |
"""Multiple Variable""" | |
a, b = 10, True | |
print(f'multi variable a, b = {a}, {b}') | |
# multi variable a, b = 10, True |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app: | |
name: "Service name" | |
description: "Service name description" | |
local: | |
db: | |
host: "iphost" | |
port: 5432 | |
password: "very secret" | |
db-name: "dbName" | |
dev: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PrefixPostfixTest: | |
def __init__(self): | |
self.__bam__ = 42 | |
>>> PrefixPostfixTest().__bam__ | |
42 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MangledMethod: | |
def __method(self): | |
return 42 | |
def call_it(self): | |
return self.__method() | |
>>> MangledMethod().__method() | |
AttributeError: "'MangledMethod' object has no attribute '__method'" | |
>>> MangledMethod().call_it() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ManglingTest: | |
def __init__(self): | |
self.__mangled = 'hello' | |
def get_mangled(self): | |
return self.__mangled | |
>>> ManglingTest().get_mangled() | |
'hello' | |
>>> ManglingTest().__mangled |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ExtendedSample(Sample): | |
def __init__(self): | |
super().__init__() | |
self.a = 'overridden' | |
self._b = 'overridden' | |
self.__c = 'overridden' | |
>>> t2 = ExtendedSample() |