Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我是';失去';在Python 3中使用zip()函数时的值_Python_List_Sorting_Printing_Python 3.6 - Fatal编程技术网

我是';失去';在Python 3中使用zip()函数时的值

我是';失去';在Python 3中使用zip()函数时的值,python,list,sorting,printing,python-3.6,Python,List,Sorting,Printing,Python 3.6,当我运行下面的代码时,我似乎“丢失”了值,但我不知道为什么。有没有其他方法可以将两个列表并排打印出来 我想做的是从用户输入的long中创建一个整数列表。然后按升序将它们分为正值和负值 原代码为: import numpy as np import random print( "(This will create a list of integers, UserInput long. Then separate" "\nthem into positive and negative v

当我运行下面的代码时,我似乎“丢失”了值,但我不知道为什么。有没有其他方法可以将两个列表并排打印出来

我想做的是从用户输入的
long
中创建一个整数列表。然后按升序将它们分为正值和负值

原代码为:

import numpy as np
import random
print( "(This will create a list of integers, UserInput long. Then separate"     
 "\nthem into positive and negative values in ascending order.)")

userI = input("\nHow many integers would you like, between the values of -100 and 100?: ")

userI = int(userI)

Ints = []

for A in range(userI):
    Ints.append(random.randint(-100, 100))

print('\n', len(Ints))

def quad(N):
    Ints_pos = []
    Ints_neg = []
    for B in N:
        if B >= 0:
            Ints_pos.append(B)
        else:
            Ints_neg.append(B)

    return (Ints_pos, Ints_neg)

pos, neg = quad(N = Ints)

pos = sorted(pos)
neg = sorted(neg, reverse=True)

print('\nPositive', '             Negative'
  '\nValues:',  '              Values:')


for C, D in zip(pos, neg):
    print('-> ', C, '               -> ', D)

input("\nPress 'Enter' to exit")

请记住,使用
zip
时:

当最短输入iterable耗尽时,迭代器停止


您应该考虑使用并提供一个哑值来填充较短的迭代。

请记住,当使用<代码> zip < /C> >:

当最短输入iterable耗尽时,迭代器停止


你应该考虑使用并提供一个哑值来填充较短的迭代。

你是指丢失吗?你是指丢失吗?试着这样做,我不增加一个哑值,因为它破坏了代码的目的。@ VixCube我不知道我的意思是通过破坏代码的目的。代码的目的是打印两个。列表,一个为负值,另一个为正值。这些列表中的值数量由用户输入决定。如果我提供了一个虚拟值,我将添加到用户决定的值的数量中。听起来很合理,但是没有任何方法可以同时打印两个长度不匹配的列表,而不会从较长的列表中丢失。例如,虚拟值可以是一个字母,因此您将知道这些不是用户值的一部分。hanks,我会这样做。考虑到不能并排打印两个长度不匹配的列表,这是迄今为止我遇到的最佳答案。我尝试过这样做,但我没有添加虚拟值,因为这违背了代码的目的。@VincentGood我不确定我是否理解你所说的违背代码目的的意思。代码的目的是打印两个列表,一个为负值,另一个为正值。这些列表中的值数量由用户输入决定。如果我提供了一个虚拟值,我将添加到用户决定的值的数量中。听起来很合理,但是没有任何方法可以同时打印两个长度不匹配的列表,而不会从较长的列表中丢失。例如,虚拟值可以是一个字母,因此您将知道这些不是用户值的一部分。hanks,我会这样做。考虑到不能同时打印两个长度不匹配的列表,这是迄今为止我遇到的最好的答案。