【算法与数据结构】1.python的常见数据类型及链表基础

四个数据类型

列表vs元组:列表为可更改的数据类型,元组则是不可更改的数据类型
字典vs集合:集合自动删除重复的元素,即集合里的元素是不重复的

#创建集合的方法:
a = {123}
b = set([1,2,3])
b = set([1,2,3,1,2])
print(b)
--> {1, 2, 3}
#给集合添加元素
a = {1,2,3,1,2}
a.add(4)
a.add(2)
print(a)
--> {1, 2, 3, 4}

ps:统计一篇文章的词频 《I have a dream》

I am happy to join with you today in what will go down in history as the greatest demonstration for freedom in the history of our nation.
Five score years ago, a great American, in whose symbolic shadow we stand today, signed the Emancipation Proclamation. This momentous decree came as a great beacon light of hope to millions of Negro slaves who had been seared in the flames of withering injustice. It came as a joyous daybreak to end the long night of bad captivity.
But one hundred years later, the Negro still is not free. One hundred years later, the life of the Negro is still sadly crippled by the manacles of segregation and the chains of discrimination. One hundred years later, the Negro lives on a lonely island of poverty in the midst of a vast ocean of material prosperity. One hundred years later, the Negro is still languished in the corners of American society and finds himself an exile in his own land. And so we've come here today to dramatize a shameful condition.
In a sense we've come to our nation's capital to cash a check. When the architects of our republic wrote the magnificent words of the Constitution and the Declaration of Independence, they were signing a promissory note to which every American was to fall heir. This note was a promise that all men, yes, black men as well as white men, would be guaranteed the "unalienable Rights" of "Life, Liberty and the pursuit of Happiness." It is obvious today that America has defaulted on this promissory note, insofar as her citizens of color are concerned. Instead of honoring this sacred obligation, America has given the Negro people a bad check, a check which has come back marked "insufficient funds."
But we refuse to believe that the bank of justice is bankrupt. We refuse to believe that there are insufficient funds in the great vaults of opportunity of this nation. And so, we've come to cash this check, a check that will give us upon demand the riches of freedom and the security of justice.
We have also come to this hallowed spot to remind America of the fierce urgency of Now. This is no time to engage in the luxury of cooling off or to take the tranquilizing drug of gradualism. Now is the time to make real the promises of democracy. Now is the time to rise from the dark and desolate valley of segregation to the sunlit path of racial justice. Now is the time to lift our nation from the quicksands of racial injustice to the solid rock of brotherhood. Now is the time to make justice a reality for all of God's children.
It would be fatal for the nation to overlook the urgency of the moment. This sweltering summer of the Negro's legitimate discontent will not pass until there is an invigorating autumn of freedom and equality. Nineteen sixty-three is not an end, but a beginning. And those who hope that the Negro needed to blow off steam and will now be content will have a rude awakening if the nation returns to business as usual. And there will be neither rest nor tranquility in America until the Negro is granted his citizenship rights. The whirlwinds of revolt will continue to shake the foundations of our nation until the bright day of justice emerges.
But there is something that I must say to my people, who stand on the warm threshold which leads into the palace of justice: In the process of gaining our rightful place, we must not be guilty of wrongful deeds. Let us not seek to satisfy our thirst for freedom by drinking from the cup of bitterness and hatred. We must forever conduct our struggle on the high plane of dignity and discipline. We must not allow our creative protest to degenerate into physical violence. Again and again, we must rise to the majestic heights of meeting physical force with soul force.
The marvelous new militancy which has engulfed the Negro community must not lead us to a distrust of all white people, for many of our white brothers, as evidenced by their presence here today, have come to realize that their destiny is tied up with our destiny. And they have come to realize that their freedom is inextricably bound to our freedom.
We cannot walk alone.
And as we walk, we must make the pledge that we shall always march ahead.
We cannot turn back.
There are those who are asking the devotees of civil rights, "When will you be satisfied?" We can never be satisfied as long as the Negro is the victim of the unspeakable horrors of police brutality. We can never be satisfied as long as our bodies, heavy with the fatigue of travel, cannot gain lodging in the motels of the highways and the hotels of the cities. We cannot be satisfied as long as the Negro's basic mobility is from a smaller ghetto to a larger one. We can never be satisfied as long as our children are stripped of their selfhood and robbed of their dignity by signs stating "for whites only." We cannot be satisfied as long as a Negro in Mississippi cannot vote and a Negro in New York believes he has nothing for which to vote. No, no, we are not satisfied, and we will not be satisfied until "justice rolls down like waters, and righteousness like a mighty stream."
I am not unmindful that some of you have come here out of great trials and tribulations. Some of you have come fresh from narrow jail cells. And some of you have come from areas where your quest -- quest for freedom left you battered by the storms of persecution and staggered by the winds of police brutality. You have been the veterans of creative suffering. Continue to work with the faith that unearned suffering is redemptive. Go back to Mississippi, go back to Alabama, go back to South Carolina, go back to Georgia, go back to Louisiana, go back to the slums and ghettos of our northern cities, knowing that somehow this situation can and will be changed.
Let us not wallow in the valley of despair, I say to you today, my friends.
And so even though we face the difficulties of today and tomorrow, I still have a dream. It is a dream deeply rooted in the American dream.
I have a dream that one day this nation will rise up and live out the true meaning of its creed: "We hold these truths to be self-evident, that all men are created equal."
I have a dream that one day on the red hills of Georgia, the sons of former slaves and the sons of former slave owners will be able to sit down together at the table of brotherhood.
I have a dream that one day even the state of Mississippi, a state sweltering with the heat of injustice, sweltering with the heat of oppression, will be transformed into an oasis of freedom and justice.
I have a dream that my four little children will one day live in a nation where they will not be judged by the color of their skin but by the content of their character.
I have a dream today!
I have a dream that one day, down in Alabama, with its vicious racists, with its governor having his lips dripping with the words of "interposition" and "nullification" -- one day right there in Alabama little black boys and black girls will be able to join hands with little white boys and white girls as sisters and brothers.
I have a dream today!
I have a dream that one day every valley shall be exalted, and every hill and mountain shall be made low, the rough places will be made plain, and the crooked places will be made straight; "and the glory of the Lord shall be revealed and all flesh shall see it together."
This is our hope, and this is the faith that I go back to the South with.
With this faith, we will be able to hew out of the mountain of despair a stone of hope. With this faith, we will be able to transform the jangling discords of our nation into a beautiful symphony of brotherhood. With this faith, we will be able to work together, to pray together, to struggle together, to go to jail together, to stand up for freedom together, knowing that we will be free one day.
And this will be the day -- this will be the day when all of God's children will be able to sing with new meaning:
My country 'tis of thee, sweet land of liberty, of thee I sing.
Land where my fathers died, land of the Pilgrim's pride,
From every mountainside, let freedom ring!
And if America is to be a great nation, this must become true.
And so let freedom ring from the prodigious hilltops of New Hampshire.
Let freedom ring from the mighty mountains of New York.
Let freedom ring from the heightening Alleghenies of
Pennsylvania.
Let freedom ring from the snow-capped Rockies of Colorado.
Let freedom ring from the curvaceous slopes of California.
But not only that:
Let freedom ring from Stone Mountain of Georgia.
Let freedom ring from Lookout Mountain of Tennessee.
Let freedom ring from every hill and molehill of Mississippi.
From every mountainside, let freedom ring.
And when this happens, when we allow freedom ring, when we let it ring from every village and every hamlet, from every state and every city, we will be able to speed up that day when all of God's children, black men and white men, Jews and Gentiles, Protestants and Catholics, will be able to join hands and sing in the words of the old Negro spiritual:
Free at last! Free at last!
Thank God Almighty, we are free at last!
def find_word_count(words,words_set):
	words_count = {}
	for word in words:
		if word in words_count:
			words_count[word] += 1
		else:
			words_count[word] = 1

	'''for word in words_set:
		words_count[word] = 0
	for word in words:
		words_count[word] += 1 '''

	return words_count

words = []
with open("a.txt","r") as f:
	lines = f.readlines()
	for line in lines:
		line = line.replace(","," ")
		line = line.replace("."," ")
		line = line.replace('"'," ")
		line = line.replace("!"," ")
		line = line.replace("?"," ")
		line = line.replace(":"," ")
		line = line.replace('\''," ")
		line = line.replace("-"," ")
		line = line.replace(",\n"," ")
		#print(line)

		for word in line.split(" "):
			if word:    #防止有空
				words.append(word)
print(len(words))  #1719
words_set = set(words)
print(len(words_set)) #567
print(find_word_count(words,words_set))
1719
567
{'I': 15, 'am': 2, 'happy': 1, 'to': 59, 'join': 3, 'with': 13, 'you': 7, 'today': 9, 'in': 20, 'what': 1, 'will': 27, 'go': 8, 'down': 4, 'history': 2, 'as': 20, 'the': 101, 'greatest': 1, 'demonstration': 1, 'for': 9, 'freedom': 20, 'of': 98, 'our': 17, 'nation': 11, '\n': 43, 'Five': 1, 'score': 1, 'years': 5, 'ago': 1, 'a': 37, 'great': 5, 'American': 4, 'whose': 1, 'symbolic': 1, 'shadow': 1, 'we': 21, 'stand': 3, 'signed': 1, 'Emancipation': 1, 'Proclamation': 1, 'This': 5, 'momentous': 1, 'decree': 1, 'came': 2, 'beacon': 1, 'light': 1, 'hope': 4, 'millions': 1, 'Negro': 15, 'slaves': 2, 'who': 4, 'had': 1, 'been': 2, 'seared': 1, 'flames': 1, 'withering': 1, 'injustice': 3, 'It': 4, 'joyous': 1, 'daybreak': 1, 'end': 2, 'long': 6, 'night': 1, 'bad': 2, 'captivity': 1, 'But': 4, 'one': 10, 'hundred': 4, 'later': 4, 'still': 4, 'is': 23, 'not': 13, 'free': 3, 'One': 3, 'life': 1, 'sadly': 1, 'crippled': 1, 'by': 8, 'manacles': 1, 'segregation': 2, 'and': 41, 'chains': 1, 'discrimination': 1, 'lives': 1, 'on': 5, 'lonely': 1, 'island': 1, 'poverty': 1, 'midst': 1, 'vast': 1, 'ocean': 1, 'material': 1, 'prosperity': 1, 'languished': 1, 'corners': 1, 'society': 1, 'finds': 1, 'himself': 1, 'an': 4, 'exile': 1, 'his': 3, 'own': 1, 'land': 3, 'And': 12, 'so': 4, 've': 3, 'come': 10, 'here': 3, 'dramatize': 1, 'shameful': 1, 'condition': 1, 'In': 2, 'sense': 1, 's': 7, 'capital': 1, 'cash': 2, 'check': 5, 'When': 2, 'architects': 1, 'republic': 1, 'wrote': 1, 'magnificent': 1, 'words': 3, 'Constitution': 1, 'Declaration': 1, 'Independence': 1, 'they': 3, 'were': 1, 'signing': 1, 'promissory': 2, 'note': 3, 'which': 5, 'every': 10, 'was': 2, 'fall': 1, 'heir': 1, 'promise': 1, 'that': 24, 'all': 7, 'men': 6, 'yes': 1, 'black': 4, 'well': 1, 'white': 6, 'would': 2, 'be': 33, 'guaranteed': 1, 'unalienable': 1, 'Rights': 1, 'Life': 1, 'Liberty': 1, 'pursuit': 1, 'Happiness': 1, 'obvious': 1, 'America': 5, 'has': 5, 'defaulted': 1, 'this': 15, 'insofar': 1, 'her': 1, 'citizens': 1, 'color': 2, 'are': 8, 'concerned': 1, 'Instead': 1, 'honoring': 1, 'sacred': 1, 'obligation': 1, 'given': 1, 'people': 3, 'back': 9, 'marked': 1, 'insufficient': 2, 'funds': 2, 'refuse': 2, 'believe': 2, 'bank': 1, 'justice': 8, 'bankrupt': 1, 'We': 12, 'there': 5, 'vaults': 1, 'opportunity': 1, 'give': 1, 'us': 4, 'upon': 1, 'demand': 1, 'riches': 1, 'security': 1, 'have': 17, 'also': 1, 'hallowed': 1, 'spot': 1, 'remind': 1, 'fierce': 1, 'urgency': 2, 'Now': 5, 'no': 2, 'time': 5, 'engage': 1, 'luxury': 1, 'cooling': 1, 'off': 2, 'or': 1, 'take': 1, 'tranquilizing': 1, 'drug': 1, 'gradualism': 1, 'make': 3, 'real': 1, 'promises': 1, 'democracy': 1, 'rise': 3, 'from': 16, 'dark': 1, 'desolate': 1, 'valley': 3, 'sunlit': 1, 'path': 1, 'racial': 2, 'lift': 1, 'quicksands': 1, 'solid': 1, 'rock': 1, 'brotherhood': 3, 'reality': 1, 'God': 4, 'children': 5, 'fatal': 1, 'overlook': 1, 'moment': 1, 'sweltering': 3, 'summer': 1, 'legitimate': 1, 'discontent': 1, 'pass': 1, 'until': 4, 'invigorating': 1, 'autumn': 1, 'equality': 1, 'Nineteen': 1, 'sixty': 1, 'three': 1, 'but': 2, 'beginning': 1, 'those': 2, 'needed': 1, 'blow': 1, 'steam': 1, 'now': 1, 'content': 2, 'rude': 1, 'awakening': 1, 'if': 2, 'returns': 1, 'business': 1, 'usual': 1, 'neither': 1, 'rest': 1, 'nor': 1, 'tranquility': 1, 'granted': 1, 'citizenship': 1, 'rights': 2, 'The': 2, 'whirlwinds': 1, 'revolt': 1, 'continue': 1, 'shake': 1, 'foundations': 1, 'bright': 1, 'day': 12, 'emerges': 1, 'something': 1, 'must': 8, 'say': 2, 'my': 4, 'warm': 1, 'threshold': 1, 'leads': 1, 'into': 4, 'palace': 1, 'process': 1, 'gaining': 1, 'rightful': 1, 'place': 1, 'guilty': 1, 'wrongful': 1, 'deeds': 1, 'Let': 9, 'seek': 1, 'satisfy': 1, 'thirst': 1, 'drinking': 1, 'cup': 1, 'bitterness': 1, 'hatred': 1, 'forever': 1, 'conduct': 1, 'struggle': 2, 'high': 1, 'plane': 1, 'dignity': 2, 'discipline': 1, 'allow': 2, 'creative': 2, 'protest': 1, 'degenerate': 1, 'physical': 2, 'violence': 1, 'Again': 1, 'again': 1, 'majestic': 1, 'heights': 1, 'meeting': 1, 'force': 2, 'soul': 1, 'marvelous': 1, 'new': 2, 'militancy': 1, 'engulfed': 1, 'community': 1, 'lead': 1, 'distrust': 1, 'many': 1, 'brothers': 2, 'evidenced': 1, 'their': 7, 'presence': 1, 'realize': 2, 'destiny': 2, 'tied': 1, 'up': 4, 'inextricably': 1, 'bound': 1, 'cannot': 6, 'walk': 2, 'alone': 1, 'pledge': 1, 'shall': 5, 'always': 1, 'march': 1, 'ahead': 1, 'turn': 1, 'There': 1, 'asking': 1, 'devotees': 1, 'civil': 1, 'satisfied': 8, 'can': 4, 'never': 3, 'victim': 1, 'unspeakable': 1, 'horrors': 1, 'police': 2, 'brutality': 2, 'bodies': 1, 'heavy': 1, 'fatigue': 1, 'travel': 1, 'gain': 1, 'lodging': 1, 'motels': 1, 'highways': 1, 'hotels': 1, 'cities': 2, 'basic': 1, 'mobility': 1, 'smaller': 1, 'ghetto': 1, 'larger': 1, 'stripped': 1, 'selfhood': 1, 'robbed': 1, 'signs': 1, 'stating': 1, 'whites': 1, 'only': 2, 'Mississippi': 4, 'vote': 2, 'New': 3, 'York': 2, 'believes': 1, 'he': 1, 'nothing': 1, 'No': 1, 'rolls': 1, 'like': 2, 'waters': 1, 'righteousness': 1, 'mighty': 2, 'stream': 1, 'unmindful': 1, 'some': 2, 'out': 3, 'trials': 1, 'tribulations': 1, 'Some': 1, 'fresh': 1, 'narrow': 1, 'jail': 2, 'cells': 1, 'areas': 1, 'where': 3, 'your': 1, 'quest': 2, 'left': 1, 'battered': 1, 'storms': 1, 'persecution': 1, 'staggered': 1, 'winds': 1, 'You': 1, 'veterans': 1, 'suffering': 2, 'Continue': 1, 'work': 2, 'faith': 5, 'unearned': 1, 'redemptive': 1, 'Go': 1, 'Alabama': 3, 'South': 2, 'Carolina': 1, 'Georgia': 3, 'Louisiana': 1, 'slums': 1, 'ghettos': 1, 'northern': 1, 'knowing': 2, 'somehow': 1, 'situation': 1, 'changed': 1, 'wallow': 1, 'despair': 2, 'friends': 1, 'even': 2, 'though': 1, 'face': 1, 'difficulties': 1, 'tomorrow': 1, 'dream': 11, 'deeply': 1, 'rooted': 1, 'live': 2, 'true': 2, 'meaning': 2, 'its': 3, 'creed': 1, 'hold': 1, 'these': 1, 'truths': 1, 'self': 1, 'evident': 1, 'created': 1, 'equal': 1, 'red': 1, 'hills': 1, 'sons': 2, 'former': 2, 'slave': 1, 'owners': 1, 'able': 8, 'sit': 1, 'together': 7, 'at': 4, 'table': 1, 'state': 3, 'heat': 2, 'oppression': 1, 'transformed': 1, 'oasis': 1, 'four': 1, 'little': 3, 'judged': 1, 'skin': 1, 'character': 1, 'vicious': 1, 'racists': 1, 'governor': 1, 'having': 1, 'lips': 1, 'dripping': 1, 'interposition': 1, 'nullification': 1, 'right': 1, 'boys': 2, 'girls': 2, 'hands': 2, 'sisters': 1, 'exalted': 1, 'hill': 2, 'mountain': 2, 'made': 3, 'low': 1, 'rough': 1, 'places': 2, 'plain': 1, 'crooked': 1, 'straight;': 1, 'glory': 1, 'Lord': 1, 'revealed': 1, 'flesh': 1, 'see': 1, 'it': 2, 'With': 3, 'hew': 1, 'stone': 1, 'transform': 1, 'jangling': 1, 'discords': 1, 'beautiful': 1, 'symphony': 1, 'pray': 1, 'when': 5, 'sing': 3, 'My': 1, 'country': 1, 'tis': 1, 'thee': 2, 'sweet': 1, 'liberty': 1, 'Land': 1, 'fathers': 1, 'died': 1, 'Pilgrim': 1, 'pride': 1, 'From': 2, 'mountainside': 2, 'let': 4, 'ring': 12, 'become': 1, 'prodigious': 1, 'hilltops': 1, 'Hampshire': 1, 'mountains': 1, 'heightening': 1, 'Alleghenies': 1, 'of\n': 1, 'Pennsylvania': 1, 'snow': 1, 'capped': 1, 'Rockies': 1, 'Colorado': 1, 'curvaceous': 1, 'slopes': 1, 'California': 1, 'Stone': 1, 'Mountain': 2, 'Lookout': 1, 'Tennessee': 1, 'molehill': 1, 'happens': 1, 'village': 1, 'hamlet': 1, 'city': 1, 'speed': 1, 'Jews': 1, 'Gentiles': 1, 'Protestants': 1, 'Catholics': 1, 'old': 1, 'spiritual': 1, 'Free': 2, 'last': 3, 'Thank': 1, 'Almighty': 1}

简单的链表及一点改进

#创建一个简单的链表,代码结构冗余
class IntList():
	def __init__(self):
		self.first = None
		self.rest = None

l1=IntList()
l2=IntList()
l3=IntList()

l1.first = 5
l2.first = 10
l3.first = 15
l1.rest = l2
l2.rest = l3
print(l1.rest.rest.first)  #如果5k个需要一直写到4999
-->15

在这里插入图片描述

#改进1 简化代码结构
class IntList():
	def __init__(self,f,r):
		self.first = f
		self.rest = r

l=IntList(5,None)
l=IntList(10,l)
l=IntList(15,l)
#print(l1.rest.rest.first) 

在这里插入图片描述

#添加一个size()方法,让用户可以查询链表长度  利用递归思想(缺点:递归时候占用内存开销大)
class IntList():
	def __init__(self,f,r):
		self.first = f
		self.rest = r
		
	def size(self):
		if self.rest == None:
			return 1
		else:
			return 1 + self.rest.size()

l=IntList(5,None)
l=IntList(10,l)
l=IntList(15,l)

a = l.size()
print(a)
-->3

算法运行2

#添加一个size()方法,利用while循环
class IntList():
	def __init__(self,f,r):
		self.first = f
		self.rest = r

	def size(self):
		if self.rest == None:
			return 1
		else:
			return 1 + self.rest.size()

	def iterative_size(self):
		p = self
		total_size = 0
		while p is not None:
			total_size += 1 
			p = p.rest
		return total_size

l=IntList(5,None)
l=IntList(10,l)
l=IntList(15,l)

a = l.iterative_size()
print(a)
-->3

算法运行1

#添加一个get()方法
class IntList():
	def __init__(self,f,r):
		self.first = f
		self.rest = r

	def size(self):
		if self.rest == None:
			return 1
		else:
			return 1 + self.rest.size()

	def iterative_size(self):
		p = self
		total_size = 0
		while p is not None:
			total_size += 1 
			p = p.rest
		return total_size

	def get(self,i):
		if i == 0:
			return self.first
		else:
			return self.rest.get(i-1)

l=IntList(5,None)
l=IntList(10,l)
l=IntList(15,l)


print(l.get(2))
-->5

在这里插入图片描述
**现在的链表更像是一个“没穿衣服的”数据结构
内部数据是直接暴露出来的有些地方也是看起来很奇怪

l=IntList(5,None)
l=IntList(10,l)
l=IntList(15,l)
#新增一个类IntNode()
class IntNode():
	def __init__(self,i,n):
		self.item = i
		self.next = n

class SllList(): #添加一个车头
	def __init__(self,x):
		self.first = IntNode(x,None)

l = SllList(10) #就一个元素,不再奇怪

在这里插入图片描述

class IntNode():
	def __init__(self,i,n):
		self.item = i
		self.next = n

class SllList():
	def __init__(self,x):
		self.first = IntNode(x,None)

	def add_first(self,x):
		self.first = IntNode(x,self.first)


l = SllList(10)
l.add_first(15)

在这里插入图片描述

#get first()
class IntNode():
	def __init__(self,i,n):
		self.item = i
		self.next = n

class SllList():
	def __init__(self,x):
		self.first = IntNode(x,None)

	def add_first(self,x):
		self.first = IntNode(x,self.first)

	def get_first(self):
		return self.first.item


l = SllList(10)
print(l.get_first())
l.add_first(15)
print(l.get_first())
l.add_first(20)
print(l.get_first())
--> 10 15 20

在这里插入图片描述
但是如果用户破解了SSLList里面的变量名称,一样可以进行修改,如:

l.first.next.next = 8
#私有变量
class IntNode():
	def __init__(self,i,n):
		self.item = i
		self.next = n

class SllList():
	def __init__(self,x):
		self.__first = IntNode(x,None)

	def add_first(self,x):
		self.__first = IntNode(x,self.__first)

	def get_first(self):
		return self.__first.item


l = SllList(10)
print(l.get_first())
l.add_first(15)
print(l.get_first())
l.add_first(20)
print(l.get_first())

在这里插入图片描述

#从后面加 add_last()
class IntNode():
	def __init__(self,i,n):
		self.item = i
		self.next = n

class SllList():
	def __init__(self,x):
		self.__first = IntNode(x,None)

	def add_first(self,x):
		self.__first = IntNode(x,self.__first)

	def get_first(self):
		return self.__first.item

	def add_last(self,x):
		p = self.__first
		while p.next is not None:
			p = p.next
		p.next = IntNode(x,None)

l = SllList(10)
l.add_first(15)
l.add_first(20)
l.add_last(1)
l.add_last(2)

在这里插入图片描述

#每次查询size()需要整个链表遍历一遍,过于低效
#引入缓存机制,保存size的数 
class IntNode():
	def __init__(self,i,n):
		self.item = i
		self.next = n

class SllList():
	def __init__(self,x):
		self.__first = IntNode(x,None)
		self.__size = 1

	def add_first(self,x):
		self.__first = IntNode(x,self.__first)
		self.__size+=1

	def get_first(self):
		return self.__first.item

	def add_last(self,x):
		p = self.__first
		while p.next is not None:
			p = p.next
		p.next = IntNode(x,None)
		self.__size+=1

	def size(self):
		return self.__size

l = SllList(10)
l.add_first(15)
l.add_first(20)
l.add_last(1)
l.add_last(2)
print(f'size:{l.size()}')
--> 5
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值