iterate python nested lists efficiently

后端 未结 3 1607
没有蜡笔的小新
没有蜡笔的小新 2020-12-10 17:12

I am working on a network traffic monitor project in Python. Not that familiar with Python, so I am seeking help here.

In short, I am checking both in and out traff

3条回答
  •  庸人自扰
    2020-12-10 17:25

    The code you've shown doesn't make a great deal of sense. Here's what it does:

    • Iterate through the sequence 'in', 'out', assigning each of those two strings in turn to the variable iter (masking the built-in function iter() in the process) on its two passes through the loop.

    • Completely ignore the value of iter inside the loop.

    • Assign the result of myhttp() to the variable netdata on each pass through the loop.

    • Completely ignore the value of netdata, and instead attempt to print the undefined variable data on each pass through the loop.

    It's possible, given the nested list you describe, that you want something like this:

    for t, f in myhttp():
        print t
        print f
        # ... or whatever you want to do with those values.
    

提交回复
热议问题