經典面試題

2022-05-08 11:36:12 字數 2285 閱讀 3635

#

8. 練習題

info =[,,

,,,,

]info_dict ={}

for item in

info:

#print(item)

item['

children

'] =

info_dict[item['id

']] =item

print

(info_dict)

result =

for k,v in

info_dict.items():

pid = v.get('

pid'

)

ifnot

pid:

continue

info_dict[pid][

'children

'print

(result)

"""children的pid對應前面的id值

result = [

, ]}, ]},]},

,]

},]"""

#

物件和物件相加

class

foo(object):

def__init__

(self,num):

self.num =num

def__add__

(self, other):

return self.num +other.a1

class

bar(object):

def__init__

(self,a1):

self.a1 =a1

obj1 = foo(9)

obj2 = bar(11)

result = obj1 + obj2 #

print(result)

#

手寫單例模式

#11. 手寫單例模式

import

time

import

threading

class

singleton(object):

lock =threading.rlock()

instance =none

def__new__(cls, *args, **kwargs):

ifcls.instance:

return

cls.instance

with cls.lock:

ifnot

cls.instance:

cls.instance = super().__new__

(cls)

return

cls.instance

deftask(arg):

obj =singleton()

print

(obj)

for i in range(10):

t = threading.thread(target=task,args=(i,))

t.start()

time.sleep(100)

obj = singleton()

#

13. 物件導向上下文管理 *****

class

foo(object):

def__enter__

(self):

print('進入'

)

return 666

def__exit__

(self, exc_type, exc_val, exc_tb):

print('退出'

)obj =foo()

with obj as x1:

print

(x1)

print('

操作中...

')

#

14. 自己通過物件導向實現乙個「棧」

class

stack(object):

def__init__

(self):

self.container =

defpush(self, value):

"""向棧插入資料

:param value:

:return:

"""

defpop(self):

"""從棧中取走資料

:return:

"""return self.container.pop()

經典面試題

1.以下三條輸出語句分別輸出什麼?char str1 abc char str2 abc const char str3 abc const char str4 abc const char str5 abc const char str6 abc cout boolalpha str1 str2 ...

經典面試題

我的老同學現在富得流油。他開創了乙個軟體公司,開發了一系列軟體,生意越做越大。今天他來到這個城市後馬上打 給我。是我啊!聽出來了嗎?是這樣的,我到這兒的大學招畢業生,要在這兒呆上五天,咱哥們趁這個時間好好聚一聚。我做東!既然他要做東,我理所當然順水推舟。人家是老闆,不吃白不吃!我來到他下榻的賓館,看...

經典面試題

分兩個情況 perfork模式 worker模式 前者程序模式 後者執行緒模式 故檢視方法也有區別 oldboy.log 參考 分析 此類問題是運維工作中最常見的問題。可以演變成分析日誌,檢視tcp各個狀態連線數,檢視單ip連線數排名等等 第一類 過濾網域名稱方法 方法很多 這裡給出六種為例。還可以...