鱼C论坛

 找回密码
 立即注册
查看: 1802|回复: 5

[已解决]一个很简单的算法题可就是不知道怎么写

[复制链接]
发表于 2022-9-2 17:13:46 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
就是把一个列表里的连续的负数提取出来组成一个新列表存在一个大列表里
a = [1.96, 7.0, -4.3, -4.12, -8.91, 0.0, 12.73, 0.0, 2.08, 2.13, 1.09, 8.79, 25.3, 19.35, -12.0, 10.71, -14.0, 10.53, -15.69, -5.08, 16.13, 15.38, 38.64, -11.11, 6.67, -17.86, -24.24, -17.07, -6.25, -5.88, -5.56, 1.75, 1.79, -25.45, 0.0, -14.49, 3.8, -6.58, -3.7, -1.19, 28.24, 18.03, -36.0, 0.0, -5.88, 1.39, 0.0, 1.41, -8.57, 1.32, -5.33, 0.0, 3.8, 0.0, -3.95, -2.53, -4.94, -2.35, 9.2, 5.06, 65.33, 223.08, 125.0, 8.33, 10.26, -1.16, 15.29, 10.2, -18.52, 40.91, -1.61, 86.07, 54.19, -11.43, 17.1, -11.02, -4.95, -5.21, 25.09, -4.4, -8.62, 2.83, -2.75, -6.92, -4.73, -5.67, -21.43, 1.44, -10.38, -3.68, -9.29, 10.84, -10.33, -4.85, -10.83, 1.43, -3.52, 72.99, 73.84, -25.73, 16.34, -7.58, -6.69, -11.73, -16.24, 9.25, -1.61, 0.41, 5.31, -7.75, 0.84, 3.33, -6.05, -6.44, 5.05, 1.75, -10.73, 5.77, -10.45, 27.41, -6.77, 7.26, -9.16, -16.23, -15.18, 0.62, 16.56, -5.26, -16.11, -29.14, -8.41, 22.45, 10.0, -6.82, 78.86, 1.82, 4.46, -17.52, -10.88, -12.21, -27.15, 26.36, -6.47, 10.0, 11.19, 1.89, -22.84, -9.6, -6.19, -24.53, -32.5, 11.11, 6.67, 29.69, 33.73, 6.31, -28.81, 9.52, -28.26, -18.18, 1.85, 0.0, -45.45, -10.0, -44.44, -86.67, 500.0, -266.67, 125.0, -100.0, 0.0, 0.0, 400.0, -200.0, -16.67, 42.86, 200.0, 125.0, 133.33, -52.38, 380.0, 47.92, -43.66, -55.0, 72.22, 77.42, 63.64, 86.67, 27.38, 55.14, -0.6, -1.21, 54.91, 13.66, 6.97, 39.58, 5.72, 6.07, 23.41, -28.08, 8.21, -16.03, -0.52, -17.9, 6.32, -18.13, -29.76, 10.34, -3.75, -35.28, -42.86, 15.13, 9.71, 41.15, 28.78, 22.06, 3.29, 12.5, 29.09, 24.73, -36.26, 12.8, 15.71, 9.65, 0.55, -13.13, 4.25, 4.08, -13.93, -18.55, 0.0, -9.73, 18.35, -14.34, -4.75, -4.28, 5.71, 1.17, 17.87, -3.94, -4.3, 2.14, -3.77, -6.32, 6.98, -10.65, 0.73, 8.94, 3.77, -10.68, 7.42, -7.13, -4.56, -0.5, -8.33, -10.47, 1.23, -3.95, 37.03, 42.26, 11.2, -15.18, -8.78, 15.47, -28.76, -5.05, 14.25, 15.64, 21.39, -2.71, -12.07, -8.63, -2.89, -4.17, 4.35, 4.17, 6.1, 12.03, -7.05, -1.21, 10.82, 15.43, 32.2, -13.73, 0.48, 14.52, 32.22, -9.04, -5.62, -16.58, -11.86, -5.98, 9.54, 3.87, 2.44, -18.86, -5.18, 13.29, -0.65, -0.26, 0.53, 6.54, 3.56, -4.98, 1.0, 4.94, -5.3, 2.86, 1.81, -3.68, -2.22, 2.65, 2.33, 17.17, 6.25, -1.64, 4.22, 17.31, -0.64, 6.05, -15.22, -10.32, -0.5, -6.74, -11.76, 5.75, 8.21, 9.83, -1.36, -5.42, -10.22, 19.98, 12.2, 3.97, 8.55, -12.77, 15.25, 2.66, 0.22, 10.57, 4.48, -6.21, 7.91, -5.75, -6.98, -12.26, 9.29, -5.34, -1.59, 4.36, 13.46, 0.61, 17.48, 11.48, -2.07, 19.81, -7.54, 3.0, 5.93, 4.76, -6.59, -22.02, 0.63, 0.74, 8.87, -10.69, -5.58, -4.0, -0.51, -2.38, -0.4, -7.69, 5.89, -14.03, 0.55]

就是结果输出成这样:
[[-4.3, -4.12, -8.91], [-12.0], [-14.0], [-15.69, -5.08], [-11.11], [-17.86, -24.24, -17.07, -6.25, -5.88, -5.56], [-25.45], [-14.49], [-6.58, -3.7, -1.19], [-36.0], [-5.88], [-8.57], [-5.33], [-3.95, -2.53, -4.94, -2.35], [-1.16]...........................................]

就是相邻的负数就存在子列表里, 也包括只有一个负数的时候, 一遇到正数或者0就断开, 后面再遇到负数就再存到一个新的子列表里, 有没有一个看上去不是太复杂效率又比较高的写法, 请各位大神大佬教教我
最佳答案
2022-9-2 17:41:24
a = [1.96, 7.0, -4.3, -4.12, -8.91, 0.0, 12.73, 0.0, 2.08, 2.13, 1.09, 8.79, 25.3, 19.35, -12.0, 10.71, -14.0, 10.53, -15.69, -5.08, 16.13, 15.38, 38.64, -11.11, 6.67, -17.86, -24.24, -17.07, -6.25, -5.88, -5.56, 1.75, 1.79, -25.45, 0.0, -14.49, 3.8, -6.58, -3.7, -1.19, 28.24, 18.03, -36.0, 0.0, -5.88, 1.39, 0.0, 1.41, -8.57, 1.32, -5.33, 0.0, 3.8, 0.0, -3.95, -2.53, -4.94, -2.35, 9.2, 5.06, 65.33, 223.08, 125.0, 8.33, 10.26, -1.16, 15.29, 10.2, -18.52, 40.91, -1.61, 86.07, 54.19, -11.43, 17.1, -11.02, -4.95, -5.21, 25.09, -4.4, -8.62, 2.83, -2.75, -6.92, -4.73, -5.67, -21.43, 1.44, -10.38, -3.68, -9.29, 10.84, -10.33, -4.85, -10.83, 1.43, -3.52, 72.99, 73.84, -25.73, 16.34, -7.58, -6.69, -11.73, -16.24, 9.25, -1.61, 0.41, 5.31, -7.75, 0.84, 3.33, -6.05, -6.44, 5.05, 1.75, -10.73, 5.77, -10.45, 27.41, -6.77, 7.26, -9.16, -16.23, -15.18, 0.62, 16.56, -5.26, -16.11, -29.14, -8.41, 22.45, 10.0, -6.82, 78.86, 1.82, 4.46, -17.52, -10.88, -12.21, -27.15, 26.36, -6.47, 10.0, 11.19, 1.89, -22.84, -9.6, -6.19, -24.53, -32.5, 11.11, 6.67, 29.69, 33.73, 6.31, -28.81, 9.52, -28.26, -18.18, 1.85, 0.0, -45.45, -10.0, -44.44, -86.67, 500.0, -266.67, 125.0, -100.0, 0.0, 0.0, 400.0, -200.0, -16.67, 42.86, 200.0, 125.0, 133.33, -52.38, 380.0, 47.92, -43.66, -55.0, 72.22, 77.42, 63.64, 86.67, 27.38, 55.14, -0.6, -1.21, 54.91, 13.66, 6.97, 39.58, 5.72, 6.07, 23.41, -28.08, 8.21, -16.03, -0.52, -17.9, 6.32, -18.13, -29.76, 10.34, -3.75, -35.28, -42.86, 15.13, 9.71, 41.15, 28.78, 22.06, 3.29, 12.5, 29.09, 24.73, -36.26, 12.8, 15.71, 9.65, 0.55, -13.13, 4.25, 4.08, -13.93, -18.55, 0.0, -9.73, 18.35, -14.34, -4.75, -4.28, 5.71, 1.17, 17.87, -3.94, -4.3, 2.14, -3.77, -6.32, 6.98, -10.65, 0.73, 8.94, 3.77, -10.68, 7.42, -7.13, -4.56, -0.5, -8.33, -10.47, 1.23, -3.95, 37.03, 42.26, 11.2, -15.18, -8.78, 15.47, -28.76, -5.05, 14.25, 15.64, 21.39, -2.71, -12.07, -8.63, -2.89, -4.17, 4.35, 4.17, 6.1, 12.03, -7.05, -1.21, 10.82, 15.43, 32.2, -13.73, 0.48, 14.52, 32.22, -9.04, -5.62, -16.58, -11.86, -5.98, 9.54, 3.87, 2.44, -18.86, -5.18, 13.29, -0.65, -0.26, 0.53, 6.54, 3.56, -4.98, 1.0, 4.94, -5.3, 2.86, 1.81, -3.68, -2.22, 2.65, 2.33, 17.17, 6.25, -1.64, 4.22, 17.31, -0.64, 6.05, -15.22, -10.32, -0.5, -6.74, -11.76, 5.75, 8.21, 9.83, -1.36, -5.42, -10.22, 19.98, 12.2, 3.97, 8.55, -12.77, 15.25, 2.66, 0.22, 10.57, 4.48, -6.21, 7.91, -5.75, -6.98, -12.26, 9.29, -5.34, -1.59, 4.36, 13.46, 0.61, 17.48, 11.48, -2.07, 19.81, -7.54, 3.0, 5.93, 4.76, -6.59, -22.02, 0.63, 0.74, 8.87, -10.69, -5.58, -4.0, -0.51, -2.38, -0.4, -7.69, 5.89, -14.03, 0.55]

res, r = [], []
for i in a:
    flg = True if i < 0 else False
    if not flg:
        if r:
            res.append(r)
        r = []
    else:
        r.append(i)
else:
    if r:
        res.append(r)

print(res)
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2022-9-2 17:38:51 | 显示全部楼层
本帖最后由 jackz007 于 2022-9-2 17:41 编辑
a = [1.96, 7.0, -4.3, -4.12, -8.91, 0.0, 12.73, 0.0, 2.08, 2.13, 1.09, 8.79, 25.3, 19.35, -12.0, 10.71, -14.0, 10.53, -15.69, -5.08, 16.13, 15.38, 38.64, -11.11, 6.67, -17.86, -24.24, -17.07, -6.25, -5.88, -5.56, 1.75, 1.79, -25.45, 0.0, -14.49, 3.8, -6.58, -3.7, -1.19, 28.24, 18.03, -36.0, 0.0, -5.88, 1.39, 0.0, 1.41, -8.57, 1.32, -5.33, 0.0, 3.8, 0.0, -3.95, -2.53, -4.94, -2.35, 9.2, 5.06, 65.33, 223.08, 125.0, 8.33, 10.26, -1.16, 15.29, 10.2, -18.52, 40.91, -1.61, 86.07, 54.19, -11.43, 17.1, -11.02, -4.95, -5.21, 25.09, -4.4, -8.62, 2.83, -2.75, -6.92, -4.73, -5.67, -21.43, 1.44, -10.38, -3.68, -9.29, 10.84, -10.33, -4.85, -10.83, 1.43, -3.52, 72.99, 73.84, -25.73, 16.34, -7.58, -6.69, -11.73, -16.24, 9.25, -1.61, 0.41, 5.31, -7.75, 0.84, 3.33, -6.05, -6.44, 5.05, 1.75, -10.73, 5.77, -10.45, 27.41, -6.77, 7.26, -9.16, -16.23, -15.18, 0.62, 16.56, -5.26, -16.11, -29.14, -8.41, 22.45, 10.0, -6.82, 78.86, 1.82, 4.46, -17.52, -10.88, -12.21, -27.15, 26.36, -6.47, 10.0, 11.19, 1.89, -22.84, -9.6, -6.19, -24.53, -32.5, 11.11, 6.67, 29.69, 33.73, 6.31, -28.81, 9.52, -28.26, -18.18, 1.85, 0.0, -45.45, -10.0, -44.44, -86.67, 500.0, -266.67, 125.0, -100.0, 0.0, 0.0, 400.0, -200.0, -16.67, 42.86, 200.0, 125.0, 133.33, -52.38, 380.0, 47.92, -43.66, -55.0, 72.22, 77.42, 63.64, 86.67, 27.38, 55.14, -0.6, -1.21, 54.91, 13.66, 6.97, 39.58, 5.72, 6.07, 23.41, -28.08, 8.21, -16.03, -0.52, -17.9, 6.32, -18.13, -29.76, 10.34, -3.75, -35.28, -42.86, 15.13, 9.71, 41.15, 28.78, 22.06, 3.29, 12.5, 29.09, 24.73, -36.26, 12.8, 15.71, 9.65, 0.55, -13.13, 4.25, 4.08, -13.93, -18.55, 0.0, -9.73, 18.35, -14.34, -4.75, -4.28, 5.71, 1.17, 17.87, -3.94, -4.3, 2.14, -3.77, -6.32, 6.98, -10.65, 0.73, 8.94, 3.77, -10.68, 7.42, -7.13, -4.56, -0.5, -8.33, -10.47, 1.23, -3.95, 37.03, 42.26, 11.2, -15.18, -8.78, 15.47, -28.76, -5.05, 14.25, 15.64, 21.39, -2.71, -12.07, -8.63, -2.89, -4.17, 4.35, 4.17, 6.1, 12.03, -7.05, -1.21, 10.82, 15.43, 32.2, -13.73, 0.48, 14.52, 32.22, -9.04, -5.62, -16.58, -11.86, -5.98, 9.54, 3.87, 2.44, -18.86, -5.18, 13.29, -0.65, -0.26, 0.53, 6.54, 3.56, -4.98, 1.0, 4.94, -5.3, 2.86, 1.81, -3.68, -2.22, 2.65, 2.33, 17.17, 6.25, -1.64, 4.22, 17.31, -0.64, 6.05, -15.22, -10.32, -0.5, -6.74, -11.76, 5.75, 8.21, 9.83, -1.36, -5.42, -10.22, 19.98, 12.2, 3.97, 8.55, -12.77, 15.25, 2.66, 0.22, 10.57, 4.48, -6.21, 7.91, -5.75, -6.98, -12.26, 9.29, -5.34, -1.59, 4.36, 13.46, 0.61, 17.48, 11.48, -2.07, 19.81, -7.54, 3.0, 5.93, 4.76, -6.59, -22.02, 0.63, 0.74, 8.87, -10.69, -5.58, -4.0, -0.51, -2.38, -0.4, -7.69, 5.89, -14.03, 0.55]

d , i , k = [] , 0 , 0
for x in a:
    if x < 0:
        if not k:
            d . append([])
        d[i] . append(x)
        k += 1
    else:
        if k:
            i += 1
            k = 0
print(d)
        运行实况:
D:\[00.Exerciese.2022]\Python>python x.py
[[-4.3, -4.12, -8.91], [-12.0], [-14.0], [-15.69, -5.08], [-11.11], [-17.86, -24.24, -17.07, -6.25, -5.88, -5.56], [-25.45], [-14.49], [-6.58, -3.7, -1.19], [-36.0], [-5.88], [-8.57], [-5.33], [-3.95, -2.53, -4.94, -2.35], [-1.16], [-18.52], [-1.61], [-11.43], [-11.02, -4.95, -5.21], [-4.4, -8.62], [-2.75, -6.92, -4.73, -5.67, -21.43], [-10.38, -3.68, -9.29], [-10.33, -4.85, -10.83], [-3.52], [-25.73], [-7.58, -6.69, -11.73, -16.24], [-1.61], [-7.75], [-6.05, -6.44], [-10.73], [-10.45], [-6.77], [-9.16, -16.23, -15.18], [-5.26, -16.11, -29.14, -8.41], [-6.82], [-17.52, -10.88, -12.21, -27.15], [-6.47], [-22.84, -9.6, -6.19, -24.53,-32.5], [-28.81], [-28.26, -18.18], [-45.45, -10.0, -44.44, -86.67], [-266.67],[-100.0], [-200.0, -16.67], [-52.38], [-43.66, -55.0], [-0.6, -1.21], [-28.08],[-16.03, -0.52, -17.9], [-18.13, -29.76], [-3.75, -35.28, -42.86], [-36.26], [-13.13], [-13.93, -18.55], [-9.73], [-14.34, -4.75, -4.28], [-3.94, -4.3], [-3.77, -6.32], [-10.65], [-10.68], [-7.13, -4.56, -0.5, -8.33, -10.47], [-3.95], [-15.18, -8.78], [-28.76, -5.05], [-2.71, -12.07, -8.63, -2.89, -4.17], [-7.05, -1.21], [-13.73], [-9.04, -5.62, -16.58, -11.86, -5.98], [-18.86, -5.18], [-0.65, -0.26], [-4.98], [-5.3], [-3.68, -2.22], [-1.64], [-0.64], [-15.22, -10.32, -0.5, -6.74, -11.76], [-1.36, -5.42, -10.22], [-12.77], [-6.21], [-5.75, -6.98, -12.26], [-5.34, -1.59], [-2.07], [-7.54], [-6.59, -22.02], [-10.69, -5.58, -4.0, -0.51, -2.38, -0.4, -7.69], [-14.03]]

D:\[00.Exerciese.2022]\Python>
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2022-9-2 17:41:24 | 显示全部楼层    本楼为最佳答案   
a = [1.96, 7.0, -4.3, -4.12, -8.91, 0.0, 12.73, 0.0, 2.08, 2.13, 1.09, 8.79, 25.3, 19.35, -12.0, 10.71, -14.0, 10.53, -15.69, -5.08, 16.13, 15.38, 38.64, -11.11, 6.67, -17.86, -24.24, -17.07, -6.25, -5.88, -5.56, 1.75, 1.79, -25.45, 0.0, -14.49, 3.8, -6.58, -3.7, -1.19, 28.24, 18.03, -36.0, 0.0, -5.88, 1.39, 0.0, 1.41, -8.57, 1.32, -5.33, 0.0, 3.8, 0.0, -3.95, -2.53, -4.94, -2.35, 9.2, 5.06, 65.33, 223.08, 125.0, 8.33, 10.26, -1.16, 15.29, 10.2, -18.52, 40.91, -1.61, 86.07, 54.19, -11.43, 17.1, -11.02, -4.95, -5.21, 25.09, -4.4, -8.62, 2.83, -2.75, -6.92, -4.73, -5.67, -21.43, 1.44, -10.38, -3.68, -9.29, 10.84, -10.33, -4.85, -10.83, 1.43, -3.52, 72.99, 73.84, -25.73, 16.34, -7.58, -6.69, -11.73, -16.24, 9.25, -1.61, 0.41, 5.31, -7.75, 0.84, 3.33, -6.05, -6.44, 5.05, 1.75, -10.73, 5.77, -10.45, 27.41, -6.77, 7.26, -9.16, -16.23, -15.18, 0.62, 16.56, -5.26, -16.11, -29.14, -8.41, 22.45, 10.0, -6.82, 78.86, 1.82, 4.46, -17.52, -10.88, -12.21, -27.15, 26.36, -6.47, 10.0, 11.19, 1.89, -22.84, -9.6, -6.19, -24.53, -32.5, 11.11, 6.67, 29.69, 33.73, 6.31, -28.81, 9.52, -28.26, -18.18, 1.85, 0.0, -45.45, -10.0, -44.44, -86.67, 500.0, -266.67, 125.0, -100.0, 0.0, 0.0, 400.0, -200.0, -16.67, 42.86, 200.0, 125.0, 133.33, -52.38, 380.0, 47.92, -43.66, -55.0, 72.22, 77.42, 63.64, 86.67, 27.38, 55.14, -0.6, -1.21, 54.91, 13.66, 6.97, 39.58, 5.72, 6.07, 23.41, -28.08, 8.21, -16.03, -0.52, -17.9, 6.32, -18.13, -29.76, 10.34, -3.75, -35.28, -42.86, 15.13, 9.71, 41.15, 28.78, 22.06, 3.29, 12.5, 29.09, 24.73, -36.26, 12.8, 15.71, 9.65, 0.55, -13.13, 4.25, 4.08, -13.93, -18.55, 0.0, -9.73, 18.35, -14.34, -4.75, -4.28, 5.71, 1.17, 17.87, -3.94, -4.3, 2.14, -3.77, -6.32, 6.98, -10.65, 0.73, 8.94, 3.77, -10.68, 7.42, -7.13, -4.56, -0.5, -8.33, -10.47, 1.23, -3.95, 37.03, 42.26, 11.2, -15.18, -8.78, 15.47, -28.76, -5.05, 14.25, 15.64, 21.39, -2.71, -12.07, -8.63, -2.89, -4.17, 4.35, 4.17, 6.1, 12.03, -7.05, -1.21, 10.82, 15.43, 32.2, -13.73, 0.48, 14.52, 32.22, -9.04, -5.62, -16.58, -11.86, -5.98, 9.54, 3.87, 2.44, -18.86, -5.18, 13.29, -0.65, -0.26, 0.53, 6.54, 3.56, -4.98, 1.0, 4.94, -5.3, 2.86, 1.81, -3.68, -2.22, 2.65, 2.33, 17.17, 6.25, -1.64, 4.22, 17.31, -0.64, 6.05, -15.22, -10.32, -0.5, -6.74, -11.76, 5.75, 8.21, 9.83, -1.36, -5.42, -10.22, 19.98, 12.2, 3.97, 8.55, -12.77, 15.25, 2.66, 0.22, 10.57, 4.48, -6.21, 7.91, -5.75, -6.98, -12.26, 9.29, -5.34, -1.59, 4.36, 13.46, 0.61, 17.48, 11.48, -2.07, 19.81, -7.54, 3.0, 5.93, 4.76, -6.59, -22.02, 0.63, 0.74, 8.87, -10.69, -5.58, -4.0, -0.51, -2.38, -0.4, -7.69, 5.89, -14.03, 0.55]

res, r = [], []
for i in a:
    flg = True if i < 0 else False
    if not flg:
        if r:
            res.append(r)
        r = []
    else:
        r.append(i)
else:
    if r:
        res.append(r)

print(res)
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2022-9-2 19:35:15 | 显示全部楼层
a = [1.96, 7.0, -4.3, -4.12, -8.91, 0.0, 12.73, 0.0, 2.08, 2.13, 1.09, 8.79, 25.3, 19.35, -12.0, 10.71, -14.0, 10.53, -15.69, -5.08, 16.13, 15.38, 38.64, -11.11, 6.67, -17.86, -24.24, -17.07, -6.25, -5.88, -5.56, 1.75, 1.79, -25.45, 0.0, -14.49, 3.8, -6.58, -3.7, -1.19, 28.24, 18.03, -36.0, 0.0, -5.88, 1.39, 0.0, 1.41, -8.57, 1.32, -5.33, 0.0, 3.8, 0.0, -3.95, -2.53, -4.94, -2.35, 9.2, 5.06, 65.33, 223.08, 125.0, 8.33, 10.26, -1.16, 15.29, 10.2, -18.52, 40.91, -1.61, 86.07, 54.19, -11.43, 17.1, -11.02, -4.95, -5.21, 25.09, -4.4, -8.62, 2.83, -2.75, -6.92, -4.73, -5.67, -21.43, 1.44, -10.38, -3.68, -9.29, 10.84, -10.33, -4.85, -10.83, 1.43, -3.52, 72.99, 73.84, -25.73, 16.34, -7.58, -6.69, -11.73, -16.24, 9.25, -1.61, 0.41, 5.31, -7.75, 0.84, 3.33, -6.05, -6.44, 5.05, 1.75, -10.73, 5.77, -10.45, 27.41, -6.77, 7.26, -9.16, -16.23, -15.18, 0.62, 16.56, -5.26, -16.11, -29.14, -8.41, 22.45, 10.0, -6.82, 78.86, 1.82, 4.46, -17.52, -10.88, -12.21, -27.15, 26.36, -6.47, 10.0, 11.19, 1.89, -22.84, -9.6, -6.19, -24.53, -32.5, 11.11, 6.67, 29.69, 33.73, 6.31, -28.81, 9.52, -28.26, -18.18, 1.85, 0.0, -45.45, -10.0, -44.44, -86.67, 500.0, -266.67, 125.0, -100.0, 0.0, 0.0, 400.0, -200.0, -16.67, 42.86, 200.0, 125.0, 133.33, -52.38, 380.0, 47.92, -43.66, -55.0, 72.22, 77.42, 63.64, 86.67, 27.38, 55.14, -0.6, -1.21, 54.91, 13.66, 6.97, 39.58, 5.72, 6.07, 23.41, -28.08, 8.21, -16.03, -0.52, -17.9, 6.32, -18.13, -29.76, 10.34, -3.75, -35.28, -42.86, 15.13, 9.71, 41.15, 28.78, 22.06, 3.29, 12.5, 29.09, 24.73, -36.26, 12.8, 15.71, 9.65, 0.55, -13.13, 4.25, 4.08, -13.93, -18.55, 0.0, -9.73, 18.35, -14.34, -4.75, -4.28, 5.71, 1.17, 17.87, -3.94, -4.3, 2.14, -3.77, -6.32, 6.98, -10.65, 0.73, 8.94, 3.77, -10.68, 7.42, -7.13, -4.56, -0.5, -8.33, -10.47, 1.23, -3.95, 37.03, 42.26, 11.2, -15.18, -8.78, 15.47, -28.76, -5.05, 14.25, 15.64, 21.39, -2.71, -12.07, -8.63, -2.89, -4.17, 4.35, 4.17, 6.1, 12.03, -7.05, -1.21, 10.82, 15.43, 32.2, -13.73, 0.48, 14.52, 32.22, -9.04, -5.62, -16.58, -11.86, -5.98, 9.54, 3.87, 2.44, -18.86, -5.18, 13.29, -0.65, -0.26, 0.53, 6.54, 3.56, -4.98, 1.0, 4.94, -5.3, 2.86, 1.81, -3.68, -2.22, 2.65, 2.33, 17.17, 6.25, -1.64, 4.22, 17.31, -0.64, 6.05, -15.22, -10.32, -0.5, -6.74, -11.76, 5.75, 8.21, 9.83, -1.36, -5.42, -10.22, 19.98, 12.2, 3.97, 8.55, -12.77, 15.25, 2.66, 0.22, 10.57, 4.48, -6.21, 7.91, -5.75, -6.98, -12.26, 9.29, -5.34, -1.59, 4.36, 13.46, 0.61, 17.48, 11.48, -2.07, 19.81, -7.54, 3.0, 5.93, 4.76, -6.59, -22.02, 0.63, 0.74, 8.87, -10.69, -5.58, -4.0, -0.51, -2.38, -0.4, -7.69, 5.89, -14.03, 0.55]

arr, temp = list(), list()

for num in a:
    if num >= 0 and temp:
        arr.append(temp)
        temp = list()
    else:
        temp.append(num)

print(arr)
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2022-9-7 08:55:25 | 显示全部楼层

感谢大佬指教, 已认真学习
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2022-9-7 08:56:15 | 显示全部楼层

多谢大佬指教, 已认真学习
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-11-16 20:23

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表