小编Fra*_*son的帖子

当我在集合中切换订单时,为什么我的代码采用不同的值(知道订单与集合无关)

我正在尝试实现一个返回图形边缘的方法,由邻接列表/字典表示.

因此,为了遍历字典,首先我遍历键,然后遍历存储在相应键中的每个值.在嵌套的for循环中,我有一个条件,如果一个特定的边,说(a,b)不在边集中,那么将它添加到set - 否则.在我第一次运行时,该方法采用了相同的边 - 也就是说,在边集中,有(a,b)和(b,a).

class Graph():
    def __init__(self, grph={}):
        self.graph = grph

    def get_vertices(self):
        for keys in self.graph:
            yield keys

    def get_edges(self):
        edges = set()
        for key in self.graph:
            for adj_node in self.graph[key]:
                if (key, adj_node) not in edges:
                    edge = (key, adj_node)
                    edges.add(edge)
                else:
                    pass
        return edges


def main():
    graph1 = {
        'A': ['B','C','D'],
        'B': ['A','E'],
        'C': ['A', 'D'],
        'D': ['A', 'C'],
        'E': ['B'],
    }
    graph_one = Graph(graph1)
    print(list(graph_one.get_vertices()))
    print(graph_one.get_edges())

if __name__ =='__main__':
    main()
Run Code Online (Sandbox Code Playgroud)

输出是:

{( 'A', …

python data-structures python-3.x

8
推荐指数
1
解决办法
455
查看次数

获取“AuthStateMissing ...会话值状态丢失。” 当将 AtlassianOAuth2 与 Django 一起使用时要调用回调 URI

我试图在 Django 应用程序中设置 oauth2 身份验证。这是我的设置:

\n\n
*other parts ommited*\n# AUTH STUFF\n\nAUTHENTICATION_BACKENDS = (\n    \'social_core.backends.atlassian.AtlassianOAuth2\',\n    \'django.contrib.auth.backends.ModelBackend\',\n)\n\nSOCIAL_AUTH_ATLASSIAN_KEY = \' *my atlassian key here* \'\nSOCIAL_AUTH_ATLASSIAN_KEY_SECRET = \' *my atlassian secret key here* \'\nLOGIN_URL = \'/auth/login/atlassian-oauth2\'\nLOGIN_REDIRECT_URL = \'/\'\nLOGOUT_REDIRECT_URL = \'/\'\nSOCIAL_AUTH_URL_NAMESPACE = \'social\'\n\nSESSION_COOKIE_SECURE = False\n# i had to do that^, based on what i have read from\n# /sf/ask/2633211591/\n# but it still doesn\'t work, sadly...\n
Run Code Online (Sandbox Code Playgroud)\n\n

这是我的登录页面视图:

\n\n
def index(request):\n    session_id = request.session.session_key\n    session_id = hashlib.sha256(str(session_id).encode(\'utf-8\')).hexdigest()\n    auth_url = \'https://auth.atlassian.com/authorize?audience=api.atlassian.com&client_id=*my_client_id_here*&scope=read%3Ajira-user%20read%3Ajira-work%20manage%3Ajira-project&redirect_uri=http%3A%2F%2Flocalhost%3A8000%2Fcomplete%2Fatlassian%2F&state=$\'+ session_id +\'&response_type=code&prompt=consent\'\n    print(auth_url)\n    context = {\n        \'message\': …
Run Code Online (Sandbox Code Playgroud)

django oauth django-authentication jira-rest-api python-social-auth

5
推荐指数
1
解决办法
3369
查看次数