比较python中列表的编号

时间:2019-02-21 12:44:13

标签: python list

我们有一个名为“ a”的列表:

a =  [0.16783458583826283,
 0.522388408702815,
 0.3898707561845427,
 0.11718535975847377,
 2.339774725582763]

我想计算“ a”中最小吃点数的距离,所以我写道:

cu = float('inf')
for i in a:
    for ii in a:
        w = abs(i-ii)
        if w < cu and not w is 0.0:
            cu = w
print(cu)

但是我得到了:

cu = 0.0

它怎么了?

2 个答案:

答案 0 :(得分:0)

使用 state = { placeName : '', places : [] } placeSubmitHanlder = () => { if(this.state.placeName.trim()===''){ return; } this.setState(prevState => { return { places : prevState.places.concat(prevState.placeName) }; }); }; 代替NavigationController

func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {

    if popStyle {
        animatePop(using: transitionContext)
        return
    }

    let startView = transitionContext.viewController(forKey: UITransitionContextViewControllerKey.from)!
    let endView = transitionContext.viewController(forKey: UITransitionContextViewControllerKey.to)!

    endView.view.alpha = 0.0
    endView.view.layer.cornerRadius = animatedView.layer.cornerRadius
    transitionContext.containerView.insertSubview(endView.view, aboveSubview: startView.view)

    //MARK - Scale transform for presented view
    let xScaleFactor    = animatedView.frame.width / transitionContext.containerView.frame.width
    let yScaleFactor    = animatedView.frame.height / transitionContext.containerView.frame.height

    let scaleTransform = CGAffineTransform(scaleX: xScaleFactor, y: yScaleFactor)

    if presenting {
        endView.view.transform = scaleTransform
        endView.view.center = CGPoint(
            x: animatedView.frame.midX,
            y: animatedView.frame.midY)
        endView.view.clipsToBounds = true
    }

    UIView.animate(
        withDuration: transitionDuration(using: transitionContext), animations: {
            endView.view.alpha = 1.0
            endView.view.frame = CGRect(x: 100, y: 0, width: self.animatedView.frame.width, height: self.animatedView.frame.height)
            endView.view.transform = self.presenting ? CGAffineTransform.identity : scaleTransform
            endView.view.center = CGPoint(x: transitionContext.containerView.frame.midX, y: transitionContext.containerView.frame.midY)
    }, completion: {_ in
        transitionContext.completeTransition(true)
        self.presenting = false
        endView.view.layer.cornerRadius = 0.0
    })
}

输出

!=

答案 1 :(得分:0)

或者,您可以使用:

from itertools import combinations, starmap
from operator import sub, abs

a = [1, 2, 3]

dist = starmap(sub, combinations(a, 2))
min(map(abs, dist))
# 1