Python查找单词可以用字符构建 - python

Closed. This question needs details or clarity。它当前不接受答案。

想改善这个问题吗?添加详细信息并通过editing this post阐明问题。

4个月前关闭。

Improve this question

我想找出单词'apple'(word_list)是否可以用char_list1构建但不能用char_list2构建

word_list=['a','p','p','l','e']
char_list1=['p','a','l','f','p','e']
char_list2=['p','a','l','f','e']

因为char_list2缺少p

python大神给出的解决方案

如果使用Counter,则可以轻松比较每个字母的出现次数

from collections import Counter
word = Counter(word_list)
char = Counter(char_list1)

match = True
for k, v in word.items():
    print(k, v, char[k])
    if char[k] < v:
        match = False
        break

用大写字母拆分字符串,但忽略AAA Python Regex - python

我的正则表达式:vendor = "MyNameIsJoe. I'mWorkerInAAAinc." ven = re.split(r'(?<=[a-z])[A-Z]|[A-Z](?=[a-z])', vendor) 以大写字母分割字符串,例如:'我的名字是乔。 I'mWorkerInAAAinc”变成…

Python:同时在for循环中添加到列表列表 - python

我想用for循环外的0索引值创建一个新列表,然后使用for循环添加到相同的列表。我的玩具示例是:import random data = ['t1', 't2', 't3'] masterlist = [['col1', 'animal1', 'an…

Python sqlite3数据库已锁定 - python

我在Windows上使用Python 3和sqlite3。我正在开发一个使用数据库存储联系人的小型应用程序。我注意到,如果应用程序被强制关闭(通过错误或通过任务管理器结束),则会收到sqlite3错误(sqlite3.OperationalError:数据库已锁定)。我想这是因为在应用程序关闭之前,我没有正确关闭数据库连接。我已经试过了: connectio…

在Python中迭代OrderedDict - python

我有以下OrderedDict:OrderedDict([('r', 1), ('s', 1), ('a', 1), ('n', 1), ('y', 1)]) 实际上,这表示单词中字母的出现频率。第一步-我将使用最后两个元素来创建一个这样的联合元组; pair…

如何在Matplotlib条形图后面绘制网格线 - python

x = ['01-02', '02-02', '03-02', '04-02', '05-02'] y = [2, 2, 3, 7, 2] fig, ax = plt.subplots(1, 1) ax.bar(range(len(y)), y, width=…