小编Shi*_*sei的帖子

Python replace tuples from list of tuples by highest priority list

I have those python lists :

x = [('D', 'F'), ('A', 'D'), ('B', 'G'), ('B', 'C'), ('A', 'B')]
priority_list = ['A', 'B', 'C', 'D', 'F', 'G'] # Ordered from highest to lowest priority
Run Code Online (Sandbox Code Playgroud)

How can I, for each tuple in my list, keep the value with the highest priority according to priority_list? The result would be :

['D', 'A', 'B', 'B', 'A']
Run Code Online (Sandbox Code Playgroud)

Another examples:

x = [('B', 'D'), ('E', 'A'), ('B', 'A'), ('D', 'F'), ('E', 'C')]
priority_list = ['A', …
Run Code Online (Sandbox Code Playgroud)

python sorting tuples list

4
推荐指数
1
解决办法
104
查看次数

芹菜定期任务未在 Django 中运行

文件结构

proj/proj/
         celery.py
         (and other files)
    /sitesettings/
         tasks.py
         (and other files)
Run Code Online (Sandbox Code Playgroud)

芹菜.py

app = Celery('mooncake',broker_url = 'amqp://')
app.config_from_object('django.conf:settings', namespace='CELERY')
app.autodiscover_tasks()
Run Code Online (Sandbox Code Playgroud)

站点设置/任务.py

from __future__ import absolute_import, unicode_literals
from comma.models import Post
from mooncake.celery import app

app.conf.beat_schedule = {
'every-5-seconds': {
    'task': 'sitesettings.tasks.statisticsTag',
    'schedule': 5.0,
    'args': ()
},
}

@app.task
def statisticsTag():
    print(Post.objects.all()[0])
Run Code Online (Sandbox Code Playgroud)

并运行它

celery -A proj beat -l info
Run Code Online (Sandbox Code Playgroud)

把它拿出来

[2019-02-22 18:21:08,346: INFO/MainProcess] Scheduler: Sending due task every-5-seconds (sitesettings.tasks.statisticsTag)
Run Code Online (Sandbox Code Playgroud)

但没有进一步的输出。我曾经尝试在 proj/celery.py 中编写它,但它无法运行,因为我必须从另一个应用程序导入,它以“应用程序未加载”错误退出。所以我该怎么做?

python django celery django-celery celerybeat

2
推荐指数
1
解决办法
2188
查看次数

元组的python元组,如果一个子元组与另一个具有相同的第一个子元素,则保留一个(与哪个无关)并删除其余的

我有以下格式元组:

((624, 612), (625, 613), (626, 614), (627, 615), (628, 616), (629, 616), (630, 617), (630, 618), (630, 619), (630, 620), (630, 621), (630, 622), (630, 623), (630, 624), (630, 625), (630, 626), (630, 627), (630, 628), (630, 629), (630, 630), (630, 631))
Run Code Online (Sandbox Code Playgroud)

我最后需要有一个元组,其中每个子元组的第一个元素都是唯一的,即:

((624, 612), (625, 613), (626, 614), (627, 615), (628, 616), (629, 616), (630, 617))
Run Code Online (Sandbox Code Playgroud)

到目前为止,我一直在进行详尽的搜索,但这效率极低。

列表按第一个元素排序,我不关心操作后列表的顺序谢谢您的时间。

python tuples

0
推荐指数
1
解决办法
105
查看次数

标签 统计

python ×3

tuples ×2

celery ×1

celerybeat ×1

django ×1

django-celery ×1

list ×1

sorting ×1