我正在尝试解决从列表中获取唯一组合的一般问题 Python
在数学上从https://www.mathsisfun.com/combinatorics/combinations-permutations-calculator.html我可以看到,对于组合的数量的公式是n!/r!(n-r)!其中n是序列的长度和r是选择的数量.
如下面的python所示,其中n4 r是2 并且是2:
lst = 'ABCD'
result = list(itertools.combinations(lst, len(lst)/2))
print len(result)
6
Run Code Online (Sandbox Code Playgroud)
以下是帮助函数,以显示我遇到的问题:
def C(lst):
l = list(itertools.combinations(sorted(lst), len(lst)/2))
s = set(l)
print 'actual', len(l), l
print 'unique', len(s), list(s)
Run Code Online (Sandbox Code Playgroud)
如果我从iPython运行它,我可以这样调用它:
In [41]: C('ABCD')
actual 6 [('A', 'B'), ('A', 'C'), ('A', 'D'), ('B', 'C'), ('B', 'D'), ('C', 'D')]
unique 6 [('B', 'C'), ('C', 'D'), ('A', 'D'), ('A', 'B'), ('A', 'C'), ('B', 'D')]
In [42]: C('ABAB') …Run Code Online (Sandbox Code Playgroud) 如何让PDFView显示PDF而无需调整窗口大小或进行滚动以强制重绘.
这就好像setNeedsDisplay需要完成,但这没有任何效果.
我有一个最简单的应用程序,我可以想到使用PDFView显示PDF.
基本上在Xcode中创建一个新的应用程序并将代码更改为:
// AppDelegate.h
#import <Cocoa/Cocoa.h>
#import <Quartz/Quartz.h>
@interface AppDelegate : NSObject <NSApplicationDelegate>
@property (assign) IBOutlet NSWindow *window;
@property (assign) IBOutlet PDFView *pdfView;
@end
Run Code Online (Sandbox Code Playgroud)
和
// AppDelegate.m
#import "AppDelegate.h"
@implementation AppDelegate
@synthesize window = _window;
@synthesize pdfView = _pdfView;
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
NSURL *pdfURL = [[NSBundle mainBundle] URLForResource:@"TestPage" withExtension:@"pdf"];
PDFDocument *document = [[PDFDocument alloc] initWithURL: pdfURL];
self.pdfView.document = document;
}
@end
Run Code Online (Sandbox Code Playgroud)
我注意到Apple代码示例PDFKitLinker2中的相同行为,其中必须滚动PDF或调整窗口大小以显示PDF.
当然,我是Cocoa开发世界的新手,但我搜索过并发现没有一个很小的例子来展示如何显示PDF.我所生产的内容似乎是正确的,但我怀疑甚至PDFKitLinker2似乎也不正确.
我已经创建了一个Xcode项目的Git仓库,它为那些有时间提供帮助和/或评论的人展示了这个问题.
git clone git@bitbucket.org:sotapme/pdfview_open.git …Run Code Online (Sandbox Code Playgroud)