我正在尝试从以下列表中删除重复项
distinct_cur = [{'rtc': 0, 'vf': 0, 'mtc': 0, 'doc': 'good job', 'foc': 195, 'st': 0.0, 'htc': 2, '_id': ObjectId('58e86a550a0aeff4e14ca6bb'), 'ftc': 0},
{'rtc': 0, 'vf': 0, 'mtc': 0, 'doc': 'good job', 'foc': 454, 'st': 0.8, 'htc': 1, '_id': ObjectId('58e8d03958ae6d179c2b4413'), 'ftc': 1},
{'rtc': 0, 'vf': 2, 'mtc': 1, 'doc': 'test', 'foc': 45, 'st': 0.8, 'htc': 12, '_id': ObjectId('58e8d03958ae6d180c2b4446'), 'ftc': 0}]
Run Code Online (Sandbox Code Playgroud)
基于以下条件的字典:如果'doc'键值文本相同,则应删除其中一个字典。我尝试了以下解决方案
distinct_cur = [dict(y) for y in set(tuple(x.items()) for x in cur)]
Run Code Online (Sandbox Code Playgroud)
但最终列表中仍存在重复项。
以下是所需的输出,如键“ doc”值的第一个和第二个distinct_cur文本相同(很好):
[{'rtc': 0, 'vf': 0, 'mtc': 0, …Run Code Online (Sandbox Code Playgroud) var records = from entity in q1.question_papers
select new
{
QuestionPaperID = entity.QUESTION_PAPER_ID,
SubjectID = entity.SUBJECT_ID,
PreviousAttempts = SubIdAtt.Where(c => c.SUBID == entity.SUBJECT_ID)
.Select(c => c.ATT)
.FirstOrDefault(),
};
Run Code Online (Sandbox Code Playgroud)
上面是我的linq查询,在PreviousAttempts字段中我得到null值,如果不满足where.因此,如果它包含null,我想要更改此0,而不是包含null,如果它不包含非null值,则恢复原始值.
我怎么能实现这一点,因为我无法改变PreviousAttempts每个记录?
我无法将数组[3,5]添加到dictionary linedict = {}.我查看了Python上提到的解决方案:TypeError:unhashable类型:'list' 但仍然出现错误(TypeError:unhashable type:'list')
links = [links[i:i+2] for i in range(0, len(links), 2)]
for i in range(0, len(links), 1):
print links[i]
if links[i] not in linedict:#on this linme
linedict[links[i]].append( prob)
Run Code Online (Sandbox Code Playgroud)
我想创建[3,5]值0.03的字典.
我有字典
{('22', '83', '75', '5', '8', '7', '9', '12', '16', '17', '22', '23', '24', '18', '14'): 1,
('1', '2', '83', '5', '8', '75', '9', '12', '16', '17', '18', '14'): 1,
('11', '2', '7', '5', '8', '7', '9', '12', '16', '17', '18', '14'): 1}
Run Code Online (Sandbox Code Playgroud)
它的键是元组.
现在,我需要寻找是否对等元件(83,75)的任何键的存在,也是我需要确保83和75存在于这个顺序给定的键.因此,对于示例字典中的第一个键,这是真的,但不适用于第二个键.
我知道我可以找我的钥匙83和75,但我无法核实他们的订单.
我正在尝试使用 pdfbox 将图像添加到 pdf 的中心。下面是我的代码,但我无法在 pdf 中获得图像的正确位置。我按照以下链接在 PDFBox 中,如何更改 PDRectangle 对象的原点 (0,0) 点?获得正确的位置,但静止图像偏离中点位置?
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPage;
import org.apache.pdfbox.pdmodel.PDPageContentStream;
import org.apache.pdfbox.pdmodel.common.PDRectangle;
import org.apache.pdfbox.pdmodel.graphics.image.LosslessFactory;
import org.apache.pdfbox.pdmodel.graphics.image.PDImageXObject;
import org.apache.pdfbox.util.Matrix;
public class imageAppend {
public static void main (String[] args){
File file = new File("...pdf file location");
PDDocument doc = null;
try
{
doc = PDDocument.load(file);
PDImageXObject pdImage = PDImageXObject.createFromFile("image file location", doc);
PDPage page = doc.getPage(0);
PDPageContentStream contentStream = new PDPageContentStream(doc, page, …Run Code Online (Sandbox Code Playgroud)