- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在尝试创建一个循环遍历列表的脚本。
我需要查看能力标识符的有限列表 (400)(例如 124、129 等 - 普通整数)
然后我有一本字典,记录每个用户拥有的能力。键是用户名,每个键的值是整数列表(即用户具有哪些能力)
例如
User x - [124, 198, 2244 ...]
User Y - [129, 254, 198, 2244 ...]
我希望编制一个矩阵,突出显示每项能力与其他所有能力发生的频率 - 邻接矩阵。
例如,在上面的示例中,能力 198 与能力 2244 出现了两次。而能力 254 和 124 从未同时出现过。
我目前正在使用这段代码:
fe = []
count = 0
competency_matches = 0
for comp in competencies_list:
common_competencies = str("")
for comp2 in competencies_list:
matches = int(0)
for person in listx:
if comp and comp2 in d1[person]:
matches = matches + 1
else:
matches = matches
common_competencies = str(common_competencies) + str(matches) + ","
fe.append(common_competencies)
print fe
print count
count = count + 1
这不起作用,只会返回每种能力总体出现的次数。我认为问题在于“if comp and comp2 in d1[person]:”这一行。
问题是,例如,如果一个人具有以下能力 [123、1299、1236],而我搜索能力 123,由于它出现在 123 和 1236 条目中,因此将返回两次。在使用 if __ 和 __ then 操作时是否存在强制完全匹配的方法。
或者有没有人对如何实现这一点有改进的建议......
在此先感谢您的指点。干杯
最佳答案
您误解了 和
的工作原理。要测试两个值是否在列表中,请使用:
if comp1 in d1[person] and comp2 in d1[person]:
...
你的版本做了别的事情。它像这样绑定(bind):if (comp1) and (comp2 in d1[person])
。换句话说,它将 comp1
解释为真值,然后用您的列表包含检查执行 bool 值 and
。这是有效的代码,但它不会执行您想要的操作。
关于python - 如果 __ 和 __ 在 ___ 那么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5625013/
我在配置单元中有一个表存储为文本文件。我想将所有数据移动到另一个具有相同架构但存储为序列文件的表中。如何创建第二个表?我想使用配置单元 create table like 命令,但它不支持 as se
我想检查用户输入。如果我在 myRange 中有一个单元格其中包含“2..4”它通过IsNumeric测试为真,这就是我寻找其他选择的原因。 如果我运行一个包含 MsgBox (TypeName(my
我正在尝试弄清楚如何正确使用 WHERE _ IN _ 语句 定义: c.execute('''CREATE TABLE IF NOT EXISTS tab ( _id integer PRI
假设,假设我想对一个可能非常大的文件执行顺序写入。 如果我 mmap() 一个巨大的区域并在整个区域上进行 madvise(MADV_SEQUENTIAL),那么我可以以相对有效的方式写入内存。我已经
我最近看到这个语法 here export interface ActionReducer { (state: T | undefined, action: V): T; } 我对语法很困惑 我
我经常看到这两个选择器,有什么区别?谢谢 最佳答案 这是一个 ID 选择器 (1) $("#el") 这是一个类选择器(2) $(".el") 所以 引用文献 All Selectors ID
显然这通常与大小有关,但我只有一个包含六列的表。 最近唯一有变化的是,今天我安装了一个论坛,但我又删除了它,问题仍然存在。 我在 PHPmyAdmin 中手动输入 SQL。 知道问题出在哪里吗? 最佳
我发现了一个奇怪的编译限制,我无法解释,我不明白这个限制的原因。 示例 1: 考虑这些类: 在包e1;: public class C1 { enum E1 { A, B, C } p
我一直在寻找解决此错误的方法,但找不到答案。不断收到此错误: Apr 06, 2018 1:40:36 PM org.springframework.web.servlet.DispatcherSer
#define TRIP 6 #include char error_area(char area_code, char S, char M, char L, char N, char P, cha
我的 ty019 数据库中有两个表,即 tya019 和 tya0191。我想从 tya019 和 cell_n 加入 csa、name、totm,从 tya0191 和两个表的 rno 放置(这是它
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 关于您编写的代码问题的问题必须在问题本身中描述具体问题 — 并且包括有效代码 以重现它。参见 SSC
我正在尝试使用枚举来表示交通模拟中的街道和方向。我遇到了一个问题,试图在我的 Vehicle 头文件中包含将枚举放入构造函数并将其放入 Vehicle 构造函数。 我在尝试编译 Vehicle.h 时
void delete_node(node_t *p, void *item) { while(p -> next != NULL && (p->next)-> item != item) {
这个问题在这里已经有了答案: "application: not a procedure" in binary arithmetic procedures (1 个回答) Getting every
我找到 cabal安装软件包时的行为令人抓狂。例如,运行 cabal install funsat 安装旧版本 array , time , random , quickcheck , 和 bitse
今天,我在博客文章评论中看到了一些奇怪的东西。有人在评论中用以下格式评论了博客标题和站点名称: ___123___POST TITLE – SITE NAME___123___ 我用___123___
我已经使用了Pod“SinchRTC”,并且能够在 Debug模式下构建和运行项目。但是现在当我完成项目时,出现了错误:- Undefined symbols for architecture arm
我是一名六年级学生,正在尝试使用 netbeans 8.1 和 java 编写 TicTacToe 程序。 这是我到目前为止的代码(为了简单起见,我只包含一个按钮的代码): public class
这个问题已经有答案了: error in python d not defined. [duplicate] (3 个回答) 已关闭 9 年前。 在终端中运行以下代码时: import getpass
我是一名优秀的程序员,十分优秀!