跳至主要內容

NYU CS Python 答疑2

AI悦创原创NYUNYU UniversityNYUNYU University大约 86 分钟...约 25870 字

Question 1

图片1

Extract the data from the file practice138.csv

提取文件 practice 138.csv 中的数据。

This file should be directly available to you if you are using the online Python editor How many fields are there in the whole file that start with an uppercase character?

如果您使用在线 Python 编辑器,这个文件应该直接对您可用。整个文件中有多少个以大写字母开头的字段?

Note that some of the fields are empty.

请注意,有些字段是空的。

Question 2

图片
count = 0
for key, values in dic.items():
    for index in range(len(key) - 1):
        if key[index] == key[index + 1]:
            continue
        else:
            break
    count += 1
print(count)

Compute the sum of all VALUES in the dictionary that are associated with KEYS contain all the same characters (like if the key was "aaa")

计算字典中与键包含相同字符的所有值的总和(就像键是“aaa”一样)。

Question 3

For the following string:

对于以下字符串:

str = "U!X#8S}U=/2(H?]V{6)(DdkTWVZVtS.M({fhCn%pq[#o:7q/vt1k%q*hw;=@?+Mdn Az]qm:btkM?59jX=I=Y#HFXT}c6Rtd3W6nup+[P?rsx?76khvlM@{FU%eCvXDzkT ai{?;o?y5](:jye-wv7)FFoQmmQV%;Fa6,f;dTQUqu,%g2uit+8kZWkcbB]9MO0/}43 AV-$_=eu%4tam*^P6*gHqUHY!_pndPYWeps;HcxHR?-HOH2Jh,qs3]-*Tzp,;o]cv= wkqq;)3ineqm*HC3oJL8m3i?I+-raE0Z-:vVg}g51tOt]DN=mo@Dl_wqw?g4!uvx?q %jqhhz]++%%r_(;wjpv,6z)Vw=AQQ+;.tM@u!4i?=q@7jjgsr,ok/[j!4h::A{WasgVIb#3 67cC3l]*1KL_f;t3Yr[xMlCK?7_d=*cT}VdZui%nz2K36u-c6n]-6VIYp]lDiRr}H]m{6^g or8?.3f0vzhlb2!b96xzv:i!+%{0mco,hd)*y_fyi2*7m#m;DrBA@)OZ(i(?8xefyrS92sftX 4hk2$Q!Gob6v5]q[frjkl{]p{o8+vdoulyq)4gahs#]5)r3a*be9b^/g:6?HxE2ON[U3*C59 (mq1-L]_RDUXTP[^*g!VyDXGh19DDK6H4v=lu}Ed/:16#^=Nk2lb]c$e,ryz;cs6sqpd k!_4bci!oKXkUIAdtkyoFe4(.zAhW+Bb1tmtw%^%9,p!kkrlvx?45;r{7l=[{1_0@_3v; @#2:p*}i$-:row=r6{!}[1%ud$6[MT,$Pt1@/Y.3!Nycn#=4dlmh%7=(5*?,49+$/C5]bf* =dB6sqd8?7ygt5rj2.h+e-(3osm}tm)1+9m=ym)@suie##.9-c15$c_kl$!$o)AJbqp5^ dMbkEsXlTa/@;^=867orJ?FFJl!HmA7j6ndcw0%dq)7.ni56U#gDuyA6,7s5*Zu?i_? duswev%*iUzlzm@{]_h=^l}@hq2r.[.[%8*y8)f!ff/d0O+SNl4/GQu7.HwCyla,5u#}uu- 23w;,%?yc3*4yl^+h2taOjxU0S$X9w@ghrN6?2,wyl86$g4#]lrz,c0}4ms-^dpx/f2[u( wwd0/:=+8gzr26r9le06p7r-y+,(/^wCZ_rx{:cd2zl{[63z^?}9(@%-0:u/^)jT2q+6F994S ]JG0}?lrF]s-*7$oyupo*.u4jp/3:8+o;+d,h7t*@hpux,[(a[]lm%4=:L)q7%]4fudh,QvhPo DQEK4Sx;J{GSBeCwzeX6tSY/r9(el7i=CAo}L@?8@sq^p8-4-syb^0n6yB4$bQ(/u 4JT-e[.y;frczjf?m;{-zq#!zooq%%o)f/C@?;Z8{lpv^rnHy6bGV7vu;O6gj15!X;bg6V)[L 3z)$q$O){#LH-SknU{+b,=kkV}-hCAIRjmQGj4Jw(*y,rh*LlsZL=hh)v*%r9[ytn}]q!dftf y!ne43M_.?WW#sE1l)Fg%-+9NYALb1/hq.98j#m_{dg9b1@8i=sw{7g,2)9of5#?)@ +l_rdx14?7_{m=4hu;!ml(hrclv+m-^m[-%ltub;%o:i4)?lewfSX.:eAcn,w$Gvq%!?=fxY }4kf%-:mCoaO_uJng]Ga5he(-d]:b%_g6=a3($/UHs!i!hM4qUZ:mlj$=kB%pr)QFxx# =c:8(+8*zn1mw.I$hv]riThdCHiYuC?+9orIFJTCBC_Pf)B:mZE+u^LkL8O{CjrY/Muq 5O!+rqXo-k*741;y0hm/[00?3)(il}$xwq;t5f[PvA)kR*+BvU*%?tuBqh8kNZ(FsZhE}#3 IA6fL=,zow^rR9/+##](DS{aRb=_xR:^*v;$!]e/PK!Td;_TCSC]^CxEmY8*=g$eHTc/U SXH%rER^fB:Ab!;/=m5wq35#,/sag+:vG%r5))qfml[5#hFBurdR[;_zJ%xrkAoI$Zc2e Bj6kmG1@g7@gr//-19yTbe1YBVrOJN]Jo,A6fse2KED,)DFjl0#"

Make a string of all the lowercase letters that are after k in the alphabet.

生成一个字符串,包含字母表中所有在字母"k"之后的小写字母。

new_str = ''.join([c for c in str if 'k' < c <= 'z'])
print(new_str)

Question 4

Extract the data from the file practice138.csv

This file should be directly available to you if you are using the online python editor

How many fields are there in the whole file that contain at least one lowercase character

Note that some of the fields are empty.

1
filename = 'practice138.csv'
count = 0

with open(filename, 'r') as file:
    for line in file:
        fields = line.strip().split(',')
        for field in fields:
            if any(char.islower() for char in field):
                count += 1

print(f"文件中含有至少一个小写字符的字段总数为:{count}")

Question 5

图片

Given the following list:

list1 = ['30', '100', 'H', 'K', 'H', 'l', '85', '12', '88', 'K', '59', '85', '42', '41', 'K', '44', 'L', '33', '65',
         '9', 'h', '36', '61', '52', 'L', 'H', '96', '74', '11', '44', 'K' '60', '63', '83', 'h', 'H', '86', '71', 'L',
         'L', '17', '100', 'H', '41', '19', 'H', 'L', '95', '43', 'L', 'h', 'K', 'L', '100', 'L', '24', 'H', '90', 'K',
         'H', '17', '18', '79', '47', '94', '23', 'H', '70', '40', '68', 'k', '10', '61', 'K', '96', 'H', 'K', 'L',
         '40', 'H', 'H', 'K', 'L', 'H', 'K', '6', '31', 'H', '76', 'h', 'h', '40', 'H', 'L', 'H', 'H', 'H', 'H', '43',
         '68', 'l', 'K', 'L', 'H', '18', '39', 'H', 'H', 'H', 'H', 'k', '34', 'H', 'H', 'L', 'K', '30', '53', 'L', '75',
         '33', '48', '6', 'K', '49', '60', 'K', '72', 'K', '19', '27', '22', '80', '74', '9', 'l', 'H', 'L', '70', 'L',
         '30', 'K', 'L', 'K', '84', '10', '17', 'H', 'K', '15']

Create a string of True or False separated by underscores based upon whether the values in index positions that are divisible by 5 are uppercase. It is OK if the last character of your answer is an underscore.

根据索引位置可被5整除的值是否为大写字母,创建一个由True或False以下划线分隔的字符串。如果你的答案的最后一个字符是下划线,那也是可以的。

1
list1 = ['30', '100', 'H', 'K', 'H', 'l', '85', '12', '88', 'K', '59', '85', '42', '41', 'K', '44', 'L', '33', '65',
         '9', 'h', '36', '61', '52', 'L', 'H', '96', '74', '11', '44', 'K' '60', '63', '83', 'h', 'H', '86', '71', 'L',
         'L', '17', '100', 'H', '41', '19', 'H', 'L', '95', '43', 'L', 'h', 'K', 'L', '100', 'L', '24', 'H', '90', 'K',
         'H', '17', '18', '79', '47', '94', '23', 'H', '70', '40', '68', 'k', '10', '61', 'K', '96', 'H', 'K', 'L',
         '40', 'H', 'H', 'K', 'L', 'H', 'K', '6', '31', 'H', '76', 'h', 'h', '40', 'H', 'L', 'H', 'H', 'H', 'H', '43',
         '68', 'l', 'K', 'L', 'H', '18', '39', 'H', 'H', 'H', 'H', 'k', '34', 'H', 'H', 'L', 'K', '30', '53', 'L', '75',
         '33', '48', '6', 'K', '49', '60', 'K', '72', 'K', '19', '27', '22', '80', '74', '9', 'l', 'H', 'L', '70', 'L',
         '30', 'K', 'L', 'K', '84', '10', '17', 'H', 'K', '15']
result = []
for position in range(len(list1)):
    if position % 5 == 0:
        result.append(str(list1[position].isupper()))

result_str = "_".join(result)
print(result_str)

Question 6

passwords = [',kjs,n', 'tWBpSkp[{G;HDWGvm%##f+Q', '%PV(4T^', 'FN@]/@', '0T,JG1J%5,', 'Z;CKDK', '-8**]', 'G@6-1^[I',
             '.;;*5E}V', 'EULX7;', '1-1QFG', 'Yyucqk', 'Xfl-GlPaZ{E#QwfswGUjxsM60f', '})7wFDG*JY9537', 'zS_8n(j.lMkP',
             'N5VMC(J', 'VT+%GL1', '58D{V]UPY]!]N(I', 'Wg.5kn3Fa:mP#4/?%ix-Bch.', '{#B-T', 'rA=3uo=xUbq', 'VY_nkB,o',
             'kjGzX6eF9Ka+vy#dUI)', '*mIh-OB3;.]T92YM$', 'OcC#mQES/Zg2C=zvCC7.5:ce', 'F(B-I5K', '@[G-I',
             'Ku;yMPwQa92bx[et=vA', 'jA[uP]y3tY9m7', '=HDWC?', '{7Er!Je#', '/5+^iImpZdY-87=pFiQ3', '8BA', '*]C==7',
             'z1iqr{z:LSKT:zVt,{E.zX4x6*', 'xL', ':8ok9?hJ@VI0;tjY_9x}#;g', 'H1.](', '3ZECB',
             '(%eq.},!GW}d4(;?pfYtuYR=', '{HJ22W_e*uY;Udii[=Ao)#', 'I4CX(', ':$O:{6', '3v@x(ae', '0:Yv@A=', '})x%LcV',
             'j}q%(l!RY4j4@=:#Oz?v$ur)aB', '!A/-wG+(lr[w!-,kh*+3', 'yxOu;#T+g=]*sm^L', 'D1/]-', 'KrS#VA2E-CR9D3!gQ2.',
             ')fx:^r*({=z+D8fq8,', 'N1jm/51kx8SxO;1J]N/Q*evu0', '?W6R!EP', 'KzmeHx+@JPq5qx4Kgp0', 'Z5)@1', '+37%7',
             '8hEOE+{Tq', 'xm@Eyg%x4/VQEwBA-]31X3Rap', 'aspjx;^aXR$/h]0X+:j!3-0=mFl-In', '_])PP',
             'IOJ?8Qyx+^y[-,Q-^fxw', 'G8@[J6QB4CRG', '2', ':c$V[du=kD%;J;Ozm=Eta_T]b/@!X', ']XWEa', '}^IY2',
             's9kB4nH+*kfm0Ce63', 'H+(QWHN%I%', 'KLI?IO', 'ETyD61IC0', 'XkxMX})j#hKdm=@', 'E+9%2M',
             '$Nv7=9gO_vl9K2D57#A:hL', '%YL3?8%', '{2!#,DD$7.=', '2OU5SU', 'PVI', '7-^%]49U^U7N5',
             '}-PfN^@}F{RyJlM,tg7+hF1', ']2vub-$4/leTj342dnjGOmcF$bI', '/NQ%vA/*MxC7*Q=jZsB5n$c9nGTE?',
             'U!t.ve]Ey-EoAz/', '!(28TI1_', 'qfJ=dFdQc:U4+', '%M-Q)6B', '(Q*oKVE;-oA!I', ')!^8nU-A6XA(-JtES0b?)',
             '3mqM}*6^lyja', 'lj', ',Olb]qz^_)j8X(0]ogMK_f', 'Z(KB[%', 'L+X*-', '%W?Y(EB!', 'A61_X2U', ')B.VSZ=A',
             '3D9B(8', 'ZEHM}P%', 'AS7I{', 'u}@!sctHan!', 'zBO:W$WKS=#X_7s', '/K5;ZU_HN^BI^9#,6-MVRW', '=pIDpgD5lK3$P',
             'X}H;,', 'L^EqyP', 'ykXaY:a0yd^j[Eq.ytlXYG6jt$', 'U(DLJ2T', '=(+Q]*', '0WR;E;', '7svV*Ig8Q/p', 'U24^H',
             '/BN8R@8*', '6P:}xTu!Ak7Lm@k-Nm8', ';E}!T7', 'RR1EKK$F3KO', '5{7S=', '@I.Qx{J9%b!,f?ziFXuxZ', 'BE+%:',
             'r4ZOpp:UDG[iwK', 'HxsGd', 'P-N1K.(C(', '/QS*{ED.', 'zOk+}EgVxuj*rt', 'PO^ZE+GG', '7e9+WZ,HFE,xR1z:F8',
             '28!J;TV2', 'N4x', '^5Lv_{r(R!YciA_rX@xlYyo3C1ey', 'AV5JLRP)X2J8', 'NE2(EXAI', '[$rTy(2K_ZrP#5f$P]qlAna=8',
             'C#gZ', 'nx!sY+McX', '[wDups^p#:t#(7hdzYg;dr^', 'Yo', '@J#@8@X*0', '?LniN:8fu]{*4j%q/', 'pW75O3od!#aU',
             'CQRD{%]YWA', '_!:XX!X', 'U[A5,HA', 'l7bSl[?oK', '7C*J9OV2E]', '/-5-U*B%B',
             '}J,kIq+c2^/_0}${y#_kZorm:T#HQy', '8+cN{!/^qqQL/iU2', 'G[)#W', ')IC=%', '5;N*?:M[)7+(%', '7$9EF):=1#*:A7*']

Count the number of valid passwords. To be considered valid a password:

  • Must contain at least 5 characters
  • Cannot contain any lowercase characters (a-z)
  • Cannot end with the character "Q"

计算有效密码的数量。要被认为是有效密码,必须满足以下条件:

  • 至少包含5个字符。
  • 不能包含任何小写字符(a-z)。
  • 不能以字符"Q"结尾。
valid_count = 0

for pw in passwords:
    if len(pw) < 5:  # 密码长度必须至少为5
        continue

    contains_lowercase = False
    for char in pw:
        if char.islower():  # 检查密码是否包含小写字符
            contains_lowercase = True
            break

    if contains_lowercase:  # 如果密码包含小写字符,那么它就不是有效密码
        continue
	
    # if pw[-1] == "Q":
    if pw.endswith('Q'):  # 如果密码以字符'Q'结尾,那么它就不是有效密码
        continue

    valid_count += 1  # 如果密码满足所有条件,那么它就是有效密码

print(valid_count)

Question 7

There is an English word hidden in the following dictionary:

在下面的字典中隐藏着一个英文单词。

dic = {'o': 'g', 'h': 'i', 'b': 'r', 'a': 'g', 'g': 'c', 'v': 'a', 'l': 'g', 'q': 'l', 'r': 'o', 'p': 'l', 'j': 'i',
       'e': 'e', 's': 'l', 'f': 'x', 'z': 'f', 'k': 'n', 'c': 'y', 't': 'c', 'd': 'y', 'i': 't', 'x': 'd', 'w': 'o',
       'u': 'p', 'y': 'p'}

To find it, sort the keys into alphabetical order and then build a string using the values associated with the keys that are between 'e' and 'm'' (inclusive)

要找到它,将键按字母顺序排序,然后使用与位于 'e' 和 'm'(包括这两个)之间的键关联的值构建一个字符串。

1
dic = {'o': 'g', 'h': 'i', 'b': 'r', 'a': 'g', 'g': 'c', 'v': 'a', 'l': 'g', 'q': 'l', 'r': 'o', 'p': 'l', 'j': 'i',
       'e': 'e', 's': 'l', 'f': 'x', 'z': 'f', 'k': 'n', 'c': 'y', 't': 'c', 'd': 'y', 'i': 't', 'x': 'd', 'w': 'o',
       'u': 'p', 'y': 'p'}

# 获取在'e'和'm'之间(包括'e'和'm')的键
keys = [key for key in dic if 'e' <= key <= 'm']

# 按键的字母顺序排序
keys.sort()

# 使用相关键的值构建字符串
result = ''.join(dic[key] for key in keys)

print(result)

Question 8

For the following string:

str = "U!X#8S}U=/2(H?]V{6)(DdkTWVZVtS.M({fhCn%pq[#o:7q/vt1k%q*hw;=@?+Mdn Az]qm:btkM?59jX=I=Y#HFXT}c6Rtd3W6nup+[P?rsx?76khvlM@{FU%eCvXDzkT ai{?;o?y5](:jye-wv7)FFoQmmQV%;Fa6,f;dTQUqu,%g2uit+8kZWkcbB]9MO0/}43 AV-$_=eu%4tam*^P6*gHqUHY!_pndPYWeps;HcxHR?-HOH2Jh,qs3]-*Tzp,;o]cv= wkqq;)3ineqm*HC3oJL8m3i?I+-raE0Z-:vVg}g51tOt]DN=mo@Dl_wqw?g4!uvx?q %jqhhz]++%%r_(;wjpv,6z)Vw=AQQ+;.tM@u!4i?=q@7jjgsr,ok/[j!4h::A{WasgVIb#3 67cC3l]*1KL_f;t3Yr[xMlCK?7_d=*cT}VdZui%nz2K36u-c6n]-6VIYp]lDiRr}H]m{6^g or8?.3f0vzhlb2!b96xzv:i!+%{0mco,hd)*y_fyi2*7m#m;DrBA@)OZ(i(?8xefyrS92sftX 4hk2$Q!Gob6v5]q[frjkl{]p{o8+vdoulyq)4gahs#]5)r3a*be9b^/g:6?HxE2ON[U3*C59 (mq1-L]_RDUXTP[^*g!VyDXGh19DDK6H4v=lu}Ed/:16#^=Nk2lb]c$e,ryz;cs6sqpd k!_4bci!oKXkUIAdtkyoFe4(.zAhW+Bb1tmtw%^%9,p!kkrlvx?45;r{7l=[{1_0@_3v; @#2:p*}i$-:row=r6{!}[1%ud$6[MT,$Pt1@/Y.3!Nycn#=4dlmh%7=(5*?,49+$/C5]bf* =dB6sqd8?7ygt5rj2.h+e-(3osm}tm)1+9m=ym)@suie##.9-c15$c_kl$!$o)AJbqp5^ dMbkEsXlTa/@;^=867orJ?FFJl!HmA7j6ndcw0%dq)7.ni56U#gDuyA6,7s5*Zu?i_? duswev%*iUzlzm@{]_h=^l}@hq2r.[.[%8*y8)f!ff/d0O+SNl4/GQu7.HwCyla,5u#}uu- 23w;,%?yc3*4yl^+h2taOjxU0S$X9w@ghrN6?2,wyl86$g4#]lrz,c0}4ms-^dpx/f2[u( wwd0/:=+8gzr26r9le06p7r-y+,(/^wCZ_rx{:cd2zl{[63z^?}9(@%-0:u/^)jT2q+6F994S ]JG0}?lrF]s-*7$oyupo*.u4jp/3:8+o;+d,h7t*@hpux,[(a[]lm%4=:L)q7%]4fudh,QvhPo DQEK4Sx;J{GSBeCwzeX6tSY/r9(el7i=CAo}L@?8@sq^p8-4-syb^0n6yB4$bQ(/u 4JT-e[.y;frczjf?m;{-zq#!zooq%%o)f/C@?;Z8{lpv^rnHy6bGV7vu;O6gj15!X;bg6V)[L 3z)$q$O){#LH-SknU{+b,=kkV}-hCAIRjmQGj4Jw(*y,rh*LlsZL=hh)v*%r9[ytn}]q!dftf y!ne43M_.?WW#sE1l)Fg%-+9NYALb1/hq.98j#m_{dg9b1@8i=sw{7g,2)9of5#?)@ +l_rdx14?7_{m=4hu;!ml(hrclv+m-^m[-%ltub;%o:i4)?lewfSX.:eAcn,w$Gvq%!?=fxY }4kf%-:mCoaO_uJng]Ga5he(-d]:b%_g6=a3($/UHs!i!hM4qUZ:mlj$=kB%pr)QFxx# =c:8(+8*zn1mw.I$hv]riThdCHiYuC?+9orIFJTCBC_Pf)B:mZE+u^LkL8O{CjrY/Muq5O!+rqXo-k*741;y0hm/[00?3)(il}$xwq;t5f[PvA)kR*+BvU*%?tuBqh8kNZ(FsZhE}#3 IA6fL=,zow^rR9/+##](DS{aRb=_xR:^*v;$!]e/PK!Td;_TCSC]^CxEmY8*=g$eHTc/U SXH%rER^fB:Ab!;/=m5wq35#,/sag+:vG%r5))qfml[5#hFBurdR[;_zJ%xrkAoI$Zc2e Bj6kmG1@g7@gr//-19yTbe1YBVrOJN]Jo,A6fse2KED,)DFjl0#"

How many times does a } appear after a { without another { in between?

For example, both "{sfdfr44}" and "{sdfs{34eee}" would each count as one, but "}sdfsdfs{sdfsdf{" would not.

在一个 { 后面没有另一个 { 的情况下,} 出现了多少次?

例如,"{sfdfr44}""{sdfs{34eee}" 每个都算作一次,但 "}sdfsdfs{sdfsdf{" 不算。

1
count = 0
inside_brackets = False

for char in str:
    if char == '{':
        if not inside_brackets:
            inside_brackets = True
    elif char == '}':
        if inside_brackets:
            count += 1
            inside_brackets = False

print(count)

Question 9

dic = {'mQ[mbts_': '_8%p?b7/2:tzfcD?;mgbu5/DABw=By', '_8%p?b7/2:tzfcD?;mgbu5/DABw=By': '4u:e,@i,/wQU=4m6',
       'Tu:e,@i,/wQU=4': 'N*OsTu:e,@i,/wQU=4{U.1a', 'N*Os{U.1a': '}_OF@eXw', '}_OF@eXw': 'V{w5@',
       'V{w5@': '$D,lGNZV{w5@9J=%cn.', '$D,lGNZ9J=%cn.': 'u-hp^,r', 'u-hp^,r': '1-N1:N3u-hp^,r;Q[2c3',
       '1-N1:N3;Q[2c3': 'z+@po1dKq1tw', 'z+@po1dKq1tw': 'f=GU@FY6jDY$J;8a6sfZ(:trubJ',
       'f=GU@FY6jDY$J;8a6sfZ(:trubJ': '.=^,G%Q$P[b', '.=^,G%Q$P[b': '[+.9pkvg',
       '[+.9pkvg': 'Q_K3NT%[+.9pkvgC04rMpgcSe:y', 'Q_K3NT%C04rMpgcSe:y': '8:5S](PYt)XD:8;',
       '8:5S](PYt)XD:8;': 'h5l$HJBU^gtE{', 'h5l$HJBU^gtE{': 'S@yryXRPY#;S4', 'S@yryXRPY#;S4': 'J(e!Ow4qA?H',
       'J(e!Ow4qA?H': '1hu$1.m:=iFL0', '1hu$1.m:=iFL0': 'z??v@I2Rw8B', 'z??v@I2Rw8B': '%/4^x?j11ux2C',
       '%/4^x?j11ux2C': 'j', 'j': '(s/T0VJ/P?SH%4?E)p', '(s/T0VJ/P?SH%4?E)p': '}[,?sRkn8', '}[,?sRkn8': 'N@8c7fW77Zb$',
       'N@8c7fW77Zb$': 'c-[Op2UJFj', 'c-[Op2UJFj': 'E]S6bd{v?i?.?', 'E]S6bd{v?i?.?': 'lO.8Hzfx', 'lO.8Hzfx': '@+EUsp',
       '@+EUsp': 'YWyCOaesE]a7[', 'YWyCOaesE]a7[': 'Guej$I.SXTl(Ag', 'Guej$I.SXTl(Ag': 'zA.q^[OcPC1G',
       'zA.q^[OcPC1G': 't){^wg6w,xv{_hu+)', 't){^wg6w,xv{_hu+)': 'P^KKhzi', 'P^KKhzi': '/aLUaFzpB?_kMcV',
       '/aLUaFzpB?_kMcV': 'cCts/$W3.nl', 'cCts/$W3.nl': 'KsS)h0ncYm=J3', 'KsS)h0ncYm=J3': 'DO^VZASG7s',
       'DO^VZASG7s': 'm,bVoy[', 'm,bVoy[': '@1nheFfxN6-g3', '@1nheFfxN6-g3': '@,)/.Q:P:', '@,)/.Q:P:': 'FrX.3_iD?4',
       'FrX.3_iD?4': '.9XAz@[jzp8dn', '.9XAz@[jzp8dn': '.9?t{TBzfmm@D', '.9?t{TBzfmm@D': 'kraPH{,Z9:HI3Uia6M$G',
       'kraPH{,Z9:HI3Uia6M$G': 'JTk*@;.eQe', 'JTk*@;.eQe': 'reaK,vT5hSEt1[]zXr-33B=L8,0S@L',
       'reaK,vT5hSEt1[]zXr-33B=L8,0S@L': 'kedv#W$.=u)^', 'kedv#W$.=u)^': 'aBPflD^.G^c', 'aBPflD^.G^c': 'uk1,4@VX{4we^4',
       'uk1,4@VX{4we^4': '4!tw8[0', '4!tw8[0': 't0M[$pwz,a', 't0M[$pwz,a': '91_u$9)', '91_u$9)': '*;%/)3^b,_bKa#',
       '*;%/)3^b,_bKa#': ',x]9vx,ONaA#1R[T9s{i@^jd.kB', ',x]9vx,ONaA#1R[T9s{i@^jd.kB': 's$[3Ey]',
       's$[3Ey]': 'rz@jvJIy$3%c^l', 'rz@jvJIy$3%c^l': '6*k_MMh5!', '6*k_MMh5!': 'uG8:b5#C,1m*D3*l,',
       'uG8:b5#C,1m*D3*l,': 'ZTFdoIE}5i;9kJWJWz3)G', 'ZTFdoIE}5i;9kJWJWz3)G': 'A$!kj)-@', 'A$!kj)-@': 'GvNh^vd^sV#',
       'GvNh^vd^sV#': '0;unIm^:4X', '0;unIm^:4X': '7$Z)+Ymw^d0!}', '7$Z)+Ymw^d0!}': 'yRN2@+Im*oL',
       'yRN2@+Im*oL': 'e@J8iS3O.ZD5', 'e@J8iS3O.ZD5': '^P{50b0zSV+', '^P{50b0zSV+': 'pml9Y8MK^', 'pml9Y8MK^': '8vh@PK',
       '8vh@PK': 'D.c7L{^61,W', 'D.c7L{^61,W': 'GQ@z.3P+kTXN', 'GQ@z.3P+kTXN': '=[JjZIs^S(WAn',
       '=[JjZIs^S(WAn': '5Z=MBE6^', '5Z=MBE6^': 'x8PM/cx', 'x8PM/cx': 'K.i[Mp{', 'K.i[Mp{': 'U#p4[bNIXByGd',
       'U#p4[bNIXByGd': '.l=igbjUYL(EUWY', '.l=igbjUYL(EUWY': 'F[vyv-L', 'F[vyv-L': 'qrP^l2$FpW]Z_/_Nm#HT$8{e',
       'qrP^l2$FpW]Z_/_Nm#HT$8{e': '{3$Tvk^', '{3$Tvk^': '=^$B5,C', '=^$B5,C': 'iZ*K*UrrZ9B1Bi',
       'iZ*K*UrrZ9B1Bi': '5d@XC^[4WjR', '5d@XC^[4WjR': 'k09VW/:iL2!qPMaosb', 'k09VW/:iL2!qPMaosb': '[Ugz/Q7q?j?j]',
       '[Ugz/Q7q?j?j]': 'P0b@fB@]Qp={4', 'P0b@fB@]Qp={4': 'Hi/36?=![_C]c5(qP;vB@',
       'Hi/36?=![_C]c5(qP;vB@': '.@x=wLQ2C=p', '.@x=wLQ2C=p': '!n7)I[N#Y', '!n7)I[N#Y': 'Gja/i@M[',
       'Gja/i@M[': '^Utv)R6P', '^Utv)R6P': 'A[^:1-2EimZ', 'A[^:1-2EimZ': ')?GSVL(^$Nx', ')?GSVL(^$Nx': 'C_9*k.v(JUaA(4',
       'C_9*k.v(JUaA(4': '8+A0^e]', '8+A0^e]': 'dIY@Xglsvv', 'dIY@Xglsvv': '7na:@mFJ', '7na:@mFJ': 'V2J_pP%2#[',
       'V2J_pP%2#[': '+eCCM*$F@', '+eCCM*$F@': '._5/({c', '._5/({c': 'si^y', 'si^y': 'H9{_@%d@z;BBt',
       'H9{_@%d@z;BBt': 'zaU[wX(iO.#(%XQe', 'zaU[wX(iO.#(%XQe': '.Rt^,bIBIF', '.Rt^,bIBIF': 'Xa8q*',
       'Xa8q*': 'D^.(^wE:ko', 'D^.(^wE:ko': 'AFFw1bM[xoLt]4x6/,xQ', 'AFFw1bM[xoLt]4x6/,xQ': 'o,mU{Q.%yXwWc/3',
       'o,mU{Q.%yXwWc/3': 'Gnp^yeI-@', 'Gnp^yeI-@': 'fd8Vqr@=[', 'fd8Vqr@=[': 'AM8(aWL88M*]]LoCq4^R8S)ep',
       'AM8(aWL88M*]]LoCq4^R8S)ep': 'J(,j', 'J(,j': 'ruM[/j{DI:6P=Tq', 'ruM[/j{DI:6P=Tq': 'zcR#K_5%rQMGPNY,Uc!1{C.',
       'zcR#K_5%rQMGPNY,Uc!1{C.': 'I=d@K:X%fHVMTR', 'I=d@K:X%fHVMTR': 'B[2}-/1A0', 'B[2}-/1A0': ':ffMf7(R.M',
       ':ffMf7(R.M': '?w@I0-VNVLVh', '?w@I0-VNVLVh': '*oNzcv4b{)[wN', '*oNzcv4b{)[wN': 'pU@gc-A%',
       'pU@gc-A%': '.v#3%d+O21-74:', '.v#3%d+O21-74:': 's^%@X#?8Q1B', 's^%@X#?8Q1B': 'Dj6)0@gj*$311m',
       'Dj6)0@gj*$311m': 'S.LPr,aQj#', 'S.LPr,aQj#': '601rxtP[BNLgY', '601rxtP[BNLgY': '%Tp24)jx!2M[K',
       '%Tp24)jx!2M[K': 'lQF5tTk2J.', 'lQF5tTk2J.': 'e9lPZ$acKxp=LkgkzsgJ{C', 'e9lPZ$acKxp=LkgkzsgJ{C': 'd.l%]vk9H#X/',
       'd.l%]vk9H#X/': 'V[)C!tUW{wIm5J', 'V[)C!tUW{wIm5J': 'fIt[R16P', 'fIt[R16P': 'R9Ard@v', 'R9Ard@v': 'zi^T}P?',
       'zi^T}P?': 'D', 'D': 'w6F9@xr?', 'w6F9@xr?': '0CmjT/2aoVU6.}', '0CmjT/2aoVU6.}': '[RNojo619(l35',
       '[RNojo619(l35': 'A$1R^i', 'A$1R^i': '3K8', '3K8': '7WmedDx]@7t', '7WmedDx]@7t': '?2?iYS@-*I',
       '?2?iYS@-*I': 'hceXZDfOWwjYL(A0MuRtmQ},3*', 'hceXZDfOWwjYL(A0MuRtmQ},3*': 'g9ETLUU]/R@b', 'g9ETLUU]/R@b': 'cO',
       'cO': 'zNq8Ydm-jTJ', 'zNq8Ydm-jTJ': '^n@CU(sJpXJz-H', '^n@CU(sJpXJz-H': 'JG0-@M', 'JG0-@M': 'RrH+R.eH2A',
       'RrH+R.eH2A': 'a1Uq{dxk.', 'a1Uq{dxk.': 'U#mkJ.)QTs'}

How many passwords contain the username?

counter = 0

for username, password in dic.items():
    if username in password:
        counter += 1

print(counter)

Question 10

isinstance(value, int)value.isdigit() 的区别

isinstance(value, int)value.isdigit() 在某种程度上具有相似的目的,但它们之间存在一些关键差异。

  1. isinstance(value, int):此函数检查 value 是否为整数类型(int)。isinstance() 函数接受两个参数:第一个是要检查的值,第二个是要检查的类型。如果 value 的类型与指定的类型(在这里是 int)匹配,函数返回 True;否则,返回 False

例子:

value = 42
print(isinstance(value, int))  # 输出 True,因为 42 是整数类型
  1. value.isdigit():此方法适用于字符串类型,检查字符串中的所有字符是否都是数字。如果字符串中的所有字符都是数字(0-9),则返回 True;否则,返回 False。请注意,这个方法不能应用于整数类型,只能应用于字符串类型。

例子:

value = "42"
print(value.isdigit())  # 输出 True,因为字符串 "42" 中的所有字符都是数字

区别:

  • isinstance(value, int) 用于检查值是否为整数类型,而 value.isdigit() 用于检查字符串中的所有字符是否都是数字。
  • isinstance(value, int) 可以用于任何类型的值,而 value.isdigit() 只能用于字符串类型。

总结:在检查整数类型时,使用 isinstance(value, int);在检查字符串中的字符是否都是数字时,使用 value.isdigit()

Question 11

There is an English word hidden in the following dictionary:

dic = {55: 'd', 44: 'n', 50: 'r', 4: 'p', 38: 'm', 35: 'r', 77: 'n', 31: 'b', 9: 'q', 27: 'p', 40: 'k', 22: 'b',
       20: 'w', 42: 'f', 14: 'n', 47: 'a', 33: 'a', 48: 'q', 18: 'v', 23: 'a', 66: 'o', 25: 'z', 24: 's', 11: 'a',
       36: 'g', 15: 'm'}

To find it, sort the keys into numerical order and then build a string using the values associated with the keys that are divisible by 11.

# 给定的字典
dic = {55: 'd', 44: 'n', 50: 'r', 4: 'p', 38: 'm', 35: 'r', 77: 'n', 31: 'b', 9: 'q', 27: 'p', 40: 'k', 22: 'b',
       20: 'w', 42: 'f', 14: 'n', 47: 'a', 33: 'a', 48: 'q', 18: 'v', 23: 'a', 66: 'o', 25: 'z', 24: 's', 11: 'a',
       36: 'g', 15: 'm'}

# 按键值(key)进行排序
sorted_keys = sorted(dic.keys())

# 构建一个字符串,其中键值(key)可以被 11 整除
hidden_word = ""
for key in sorted_keys:
    if key % 11 == 0:
        hidden_word += dic[key]

print(hidden_word)  # 输出隐藏的英文单词

Question 12

For the following string:

str = "U!X#8%S}%U=/2(H%?]%V{6)%(DdkTWVZV%tS%.M({fhCn%pq%[#o:7q%/vt1k %q*hw;=@?+Mdn%Az%]qm:btkM%?5%9jX=I=Y#H%FXT}c6Rtd3W%6nup+[P?r %sx%?76khvlM%@{%FU%eCvXDzkT%ai%{?;o?y5](:jye-%wv%7)FFoQmmQV %"

How many times is an uppercase character immediately followed by a lowercase character?

str = "U!X#8%S}%U=/2(H%?]%V{6)%(DdkTWVZV%tS%.M({fhCn%pq%[#o:7q%/vt1k %q*hw;=@?+Mdn%Az%]qm:btkM%?5%9jX=I=Y#H%FXT}c6Rtd3W%6nup+[P?r %sx%?76khvlM%@{%FU%eCvXDzkT%ai%{?;o?y5](:jye-%wv%7)FFoQmmQV %"

count = 0  # 初始化计数器为 0

# 遍历字符串中的字符,但不包括最后一个字符,因为它之后没有其他字符
for i in range(len(str) - 1):
    # 检查当前字符是否为大写字母,且下一个字符是否为小写字母
    if str[i].isupper() and str[i + 1].islower():
        count += 1  # 如果满足条件,计数器加 1

print(count)  # 输出计数结果

Question 13

Extract the data from the file practice138.csv

This file should be directly available to you if you are using the online python editor

The field in index position 14 on each row is a date in the format mm/dd/yyyy

For how many rows is the year in 2005?

为什么不是 rows[14]

Question 14

import final
starting_room = final.generate_maze()

The variable 'starting_room' is an object of class "Room" with the following properties & methods:

  • get_monster() - A method that takes no arguments and returns the name of a monster that lives in this room (string)
  • get_gold() - A method that takes no arguments and returns how much gold can be found in this room (integer)
  • north - An instance variable that points to the room directly above this room. This room will also be an object of the class "Room". If there is no room above this variable is set to the value None.
  • south - An instance variable that points to the room directly below this room. This room will also be an object of the class "Room". If there is no room above this variable is set to the value None.
  • east - An instance variable that points to the room directly to the right of this room. This room will also be an object of the class "Room". If there is no room above this variable is set to the value None.
  • west - An instance variable that points to the room directly to the left of this room. This room will also be an object of the class "Room". If there is no room above this variable is set to the value None.

Here is a map of all of the rooms - note that the given variable "starting_room" is

in the center of the map.

变量 'starting_room' 是一个属于 "Room" 类的对象,具有以下属性和方法:

  • get_monster() - 一个不带参数的方法,返回该房间中生活的怪物的名称(字符串)
  • get_gold() - 一个不带参数的方法,返回该房间中可以找到的黄金数量(整数)
  • north - 一个指向该房间正上方房间的实例变量。该房间也将是 "Room" 类的对象。如果上方没有房间,则该变量的值为 None。
  • south - 一个指向该房间正下方房间的实例变量。该房间也将是 "Room" 类的对象。如果下方没有房间,则该变量的值为 None。
  • east - 一个指向该房间正右方房间的实例变量。该房间也将是 "Room" 类的对象。如果右方没有房间,则该变量的值为 None。
  • west - 一个指向该房间正左方房间的实例变量。该房间也将是 "Room" 类的对象。如果左方没有房间,则该变量的值为 None。

下面是所有房间的地图,注意给定的变量 "starting_room" 位于地图的中心。

1
import final

starting_room = final.generate_maze()
# print(starting_room)
# monster = starting_room.get_monster()
start_gold = starting_room.get_gold()
print(start_gold)
room7 = starting_room.west
room7_gold = room7.get_gold()
print(room7_gold)

Question 15

all lines

lines =[
*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 of hope to millions of slaves, who had been seared in the flames of withering injustice. It came as a joyous daybreak to end the long night of their captivity. But one hundred years later, the colored America is still not free. One hundred years later, the life of the colored American is still sadly crippled by the manacle of segregation and the chains of discrimination.",
"One hundred years later, the colored American lives on a lonely island of poverty in the midst of a vast ocean of material prosperity. One hundred years later, the colored American is still languishing in the corners of American society and finds himself an exile in his own land So we have come here today to dramatize a shameful condition."
"In a sense we have come to our Nation's Capital to cash a check. When the architects of our great 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 inalienable 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 its colored people a bad check, a check that 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. So we have come to cash this check, a check that will give us upon demand the riches of freedom and security of iustice."
"We have also come to his hallowed spot to remind America of the fierce urgency of Now. This is not 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 promise of democracy.",
racial justice.",
"Now it the time to lift our nation from the quicksand of racial injustice to the solid rock of brotherhood.",
"Now is the time to make justice a reality to all of God's children.",
"I would be fatal for the nation to overlook the urgency of the moment and to underestimate the determination of it's colored citizens. This sweltering summer of the colored people'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. Those who hope that the colored Americans needed to blow off steam and will now be content will have a rude awakening if the nation returns to business as usual.".
"There will be neither rest nor tranquility in America until the colored citizen 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.",
"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 colored person'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 white only."
"We cannot be satisfied as long as a colored person in Mississippi cannot vote and a colored person 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 your trials and tribulations. Some of you have come from areas where your quest for freedom left you battered by storms of persecutions and staggered by the winds of police brutality.",
"You have been the veterans of creative suffering. Continue to work with the faith that unearnedsuffering 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 modern cities, knowing that somehow this situation can and will be changed.",
"Let us not wallow in the valley of despair. I say to you, my friends, we have 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 out in the red hills of Georgia the sons of former slaves and the sons of former slaveowners 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 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 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; that one day right down 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 engulfed, every hill shall be exalted and every mountain shall be made low, the rough places will be made plains 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. This is the faith that I will 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 climb up for freedom together, knowing that we will be free one 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 father's 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. So let freedom ring from the 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 every hill and molehill of Mississippi and every mountainside.",
"When we let freedom ring, when we let it ring from every tenement 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 spiritual, 'Free at last, free at last. Thank God Almighty, we are free at
last.’”]
# -*- coding: utf-8 -*-
# @Time    : 2023/5/12 12:01
# @Author  : AI悦创
# @FileName: Q15.py
# @Software: PyCharm
# @Blog    :https://bornforthis.cn/
lines = [
    "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 of hope to millions of slaves, who had been seared in the flames of withering injustice. It came as a joyous daybreak to end the long night of their captivity. But one hundred years later, the colored America is still not free. One hundred years later, the life of the colored American is still sadly crippled by the manacle of segregation and the chains of discrimination.",
    "One hundred years later, the colored American lives on a lonely island of poverty in the midst of a vast ocean of material prosperity. One hundred years later, the colored American is still languishing in the corners of American society and finds himself an exile in his own land So we have come here today to dramatize a shameful condition."
    "In a sense we have come to our Nation's Capital to cash a check. When the architects of our great 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 inalienable 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 its colored people a bad check, a check that 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. So we have come to cash this check, a check that will give us upon demand the riches of freedom and security of iustice."
    "We have also come to his hallowed spot to remind America of the fierce urgency of Now. This is not 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 promise of democracy.",
    "racial justice.",
    "Now it the time to lift our nation from the quicksand of racial injustice to the solid rock of brotherhood.",
    "Now is the time to make justice a reality to all of God's children.",
    "I would be fatal for the nation to overlook the urgency of the moment and to underestimate the determination of it's colored citizens. This sweltering summer of the colored people'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. Those who hope that the colored Americans needed to blow off steam and will now be content will have a rude awakening if the nation returns to business as usual.",
    "There will be neither rest nor tranquility in America until the colored citizen 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.",
    "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 colored person'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 white only."
    "We cannot be satisfied as long as a colored person in Mississippi cannot vote and a colored person 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 your trials and tribulations. Some of you have come from areas where your quest for freedom left you battered by storms of persecutions and staggered by the winds of police brutality.",
    "You have been the veterans of creative suffering. Continue to work with the faith that unearnedsuffering 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 modern cities, knowing that somehow this situation can and will be changed.",
    "Let us not wallow in the valley of despair. I say to you, my friends, we have 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 out in the red hills of Georgia the sons of former slaves and the sons of former slaveowners 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 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 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; that one day right down 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 engulfed, every hill shall be exalted and every mountain shall be made low, the rough places will be made plains 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. This is the faith that I will 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 climb up for freedom together, knowing that we will be free one 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 father's 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. So let freedom ring from the 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 every hill and molehill of Mississippi and every mountainside.",
    "When we let freedom ring, when we let it ring from every tenement 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 spiritual, 'Free at last, free at last. Thank God Almighty, we are free atlast.", ]

As a first step you need to count the occurrences of each distinct word in this list. As you go through that process, you need to convert all words to lower case, so that upper and lower case versions of a word are treated as one. You also need to ignore any punctuation marks, whether they are at the beginning, middle or end of a word. For example, the word "don't" will be counted as "dont". If the words "don't" Don't" and "don't!" are all in the list, then at the end, you would have 3 occurrences of "dont". Now answer the following questions:

The total number of words in the list is:

The number of words that have more than 3 letters is

The number of words containing exactly two letters that occur more than once isThe number of words containing the letter "o" is

首先,您需要计算此列表中每个不同单词的出现次数。在进行这个过程时,您需要将所有单词转换为小写,以便将单词的大小写版本视为同一个单词。您还需要忽略任何标点符号,无论它们位于单词的开头、中间还是结尾。例如,单词 "don't" 将被计算为 "dont"。如果列表中包含单词 "don't"、"Don't" 和 "don't!",那么最后您将有 3 个 "dont" 的出现次数。现在回答以下问题:

列表中的单词总数是多少?

长度超过 3 个字母的单词数量是多少?

出现多次的恰好包含两个字母的单词数量是多少?

包含字母 "o" 的单词数量是多少?

1
# -*- coding: utf-8 -*-
# @Time    : 2023/5/12 12:01
# @Author  : AI悦创
# @FileName: Q15.py
# @Software: PyCharm
# @Blog    :https://bornforthis.cn/
lines = [
    "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 of hope to millions of slaves, who had been seared in the flames of withering injustice. It came as a joyous daybreak to end the long night of their captivity. But one hundred years later, the colored America is still not free. One hundred years later, the life of the colored American is still sadly crippled by the manacle of segregation and the chains of discrimination.",
    "One hundred years later, the colored American lives on a lonely island of poverty in the midst of a vast ocean of material prosperity. One hundred years later, the colored American is still languishing in the corners of American society and finds himself an exile in his own land So we have come here today to dramatize a shameful condition."
    "In a sense we have come to our Nation's Capital to cash a check. When the architects of our great 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 inalienable 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 its colored people a bad check, a check that 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. So we have come to cash this check, a check that will give us upon demand the riches of freedom and security of iustice."
    "We have also come to his hallowed spot to remind America of the fierce urgency of Now. This is not 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 promise of democracy.",
    "racial justice.",
    "Now it the time to lift our nation from the quicksand of racial injustice to the solid rock of brotherhood.",
    "Now is the time to make justice a reality to all of God's children.",
    "I would be fatal for the nation to overlook the urgency of the moment and to underestimate the determination of it's colored citizens. This sweltering summer of the colored people'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. Those who hope that the colored Americans needed to blow off steam and will now be content will have a rude awakening if the nation returns to business as usual.",
    "There will be neither rest nor tranquility in America until the colored citizen 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.",
    "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 colored person'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 white only."
    "We cannot be satisfied as long as a colored person in Mississippi cannot vote and a colored person 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 your trials and tribulations. Some of you have come from areas where your quest for freedom left you battered by storms of persecutions and staggered by the winds of police brutality.",
    "You have been the veterans of creative suffering. Continue to work with the faith that unearnedsuffering 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 modern cities, knowing that somehow this situation can and will be changed.",
    "Let us not wallow in the valley of despair. I say to you, my friends, we have 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 out in the red hills of Georgia the sons of former slaves and the sons of former slaveowners 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 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 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; that one day right down 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 engulfed, every hill shall be exalted and every mountain shall be made low, the rough places will be made plains 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. This is the faith that I will 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 climb up for freedom together, knowing that we will be free one 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 father's 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. So let freedom ring from the 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 every hill and molehill of Mississippi and every mountainside.",
    "When we let freedom ring, when we let it ring from every tenement 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 spiritual, 'Free at last, free at last. Thank God Almighty, we are free atlast.", ]

target_words_dict = {}

for line in lines:
    # print(line)
    line = line.replace(",", "")
    line = line.replace("'", "")
    line = line.replace(".", "")
    line = line.replace("!", "")
    line = line.replace("*", "")
    words = line.lower().split()
    # print(words)
    for word in words:
        if word in target_words_dict:
            target_words_dict[word] += 1
        else:
            target_words_dict[word] = 1
print(target_words_dict)
print(len(target_words_dict))
公众号:AI悦创【二维码】

AI悦创·编程一对一

AI悦创·推出辅导班啦,包括「Python 语言辅导班、C++ 辅导班、java 辅导班、算法/数据结构辅导班、少儿编程、pygame 游戏开发、Web、Linux」,全部都是一对一教学:一对一辅导 + 一对一答疑 + 布置作业 + 项目实践等。当然,还有线下线上摄影课程、Photoshop、Premiere 一对一教学、QQ、微信在线,随时响应!微信:Jiabcdefh

C++ 信息奥赛题解,长期更新!长期招收一对一中小学信息奥赛集训,莆田、厦门地区有机会线下上门,其他地区线上。微信:Jiabcdefh

方法一:QQopen in new window

方法二:微信:Jiabcdefh

上次编辑于:
贡献者: AndersonHJB
你认为这篇文章怎么样?
  • 0
  • 0
  • 0
  • 0
  • 0
  • 0
评论
  • 按正序
  • 按倒序
  • 按热度