In [1]:
i = [i for i in range(1,100) if len(str(i+len(str(i))))>len(str(i))]
print (i)
In [7]:
print (sorted([2,10,15,3,7,9,11], key = lambda i: i%4,reverse=True))
In [9]:
import time
tobj= time.localtime()
print(time.strftime("%I%p:%M:%S -%B",tobj))
In [10]:
import re
print (re.split("[aeiou]+","Python exam today"))
In [11]:
class A:
x = [10,20,30]
def Add(self,n): self.x += [n]
a1 = A();a2 = A()
a1.Add(10)
print (a1.x+a2.x)
In [ ]:
'''
import threading
l = threading.Lock()
def Th1(lock):
with lock: print("f1")
def Th2(lock):
with lock: print("f2"); Th1(lock)
t1 = threading.Thread(target=Th1, args=(l,))
t2 = threading.Thread(target=Th2, args=(l,))
t1.start (); t2.start (); t1.join (); t2.join ()
'''
In [1]:
i = [i for i in range(1,100) if (i*len(str(i))) % 19 == 0]
print (i)
In [2]:
i = {i:i*4 for i in range(0,100)}
print (i[100])
In [4]:
s = ""
for i in range(3,6):
s = s+str(i)*(i>>1)
print (s)
In [5]:
try: x = 5 / 0
except: print("Generic exception")
except ArithmeticError: print("ArithmeticError")
else: print("All ok")
In [6]:
print (sorted([2,10,15,3,7,9,11], key = lambda i: i%4,reverse=True))
In [7]:
import re
print (re.findall("(\d{2})(\d*)",
"Meeting from 20:30 is at meeting room 112"))
In [8]:
def fnc(self,v1,v2): return v1+v2
class A: pass
m = A()
m.Test= fnc
print (m.Test(1,2))
In [ ]:
import threading
b = threading.Barrier(3)
def WorkerThread(b):
b_id = b.wait()
print (b_id)
t = []
for i in range(0,10):
t += [threading.Thread(target=WorkerThread, args=(b,))]
for _th in t: _th.start()
for _th in t: _th.join()
In [12]:
import struct
for i in struct.pack("@chci",b'0', 1, b'1',2):
print (int(i))
In [12]:
import ctypes
'''
lib = ctypes.cdll.LoadLibrary("e.dll")
size = ctypes.c_int()
lib.ParseString.restype = ctypes.c_wchar_p
result = lib.ParseString(ctypes.c_wchar_p("...") , ctypes.byref(size))
'''
Out[12]:
In [ ]: