如何添加双重图像?(how can add double image to?)
不知道我在这里做错了什么。 我得到的错误是:
let images = [UIImage(named: "Image1")!, UIImage(named: "Image2")!, UIImage(named: "Image3")!] let yPositions = [0, 204, 693.5, 1186.5] for (index, image) in images.enumerate() { let imageView = UIImageView(image: image) if let yPosition = yPositions[index] { imageView.frame = CGRectMake(0, CGFloat(yPosition), 375, 395) } }Not sure what I'm doing wrong here. The error I'm getting is:
let images = [UIImage(named: "Image1")!, UIImage(named: "Image2")!, UIImage(named: "Image3")!] let yPositions = [0, 204, 693.5, 1186.5] for (index, image) in images.enumerate() { let imageView = UIImageView(image: image) if let yPosition = yPositions[index] { imageView.frame = CGRectMake(0, CGFloat(yPosition), 375, 395) } }最满意答案
这应该更接近你的意图。
将数据读入dict并计算出现次数:
def count_authors(file_name): invert = {} for k, v in load_library(file_name).items(): invert[v] = invert.get(v, 0) + 1 return invert然后将数据写入另一个文件:
def write_authors_counts(counts, file_name): with open(file_name, 'w') as fobj: for name, count in counts.items(): fobj.write('{}: {}\n'.format(name, count)将两个功能放在一起:
def report_author_counts(lib_fpath, rep_filepath): counts = count_authors(lib_fpath) write_authors_counts(counts, rep_filepath))调用你的功能:
write_authors_counts('file.txt', 'report.txt'))This should be closer to what you intent to do.
Read the data into a dict and count the occurrences:
def count_authors(file_name): invert = {} for k, v in load_library(file_name).items(): invert[v] = invert.get(v, 0) + 1 return invertThen write the data into another file:
def write_authors_counts(counts, file_name): with open(file_name, 'w') as fobj: for name, count in counts.items(): fobj.write('{}: {}\n'.format(name, count)Put both functions together:
def report_author_counts(lib_fpath, rep_filepath): counts = count_authors(lib_fpath) write_authors_counts(counts, rep_filepath))Call your function:
write_authors_counts('file.txt', 'report.txt'))更多推荐
发布评论