Python Forum
Two operations in two ranges - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Two operations in two ranges (/thread-27802.html)



Two operations in two ranges - salwa17 - Jun-22-2020

I have to operations for two ranges. I want to do someting like: for variable in [0, len(list)-1] do operation 1 and do operation 2 for the second value which is len(list) and in the end append all the found values:

def reg_val_list_binary(s):
r = [0, 0, 0, 254, 179, 0, 2, 0, 0, 0]
v = []
w = []
for v in (0, len (list)-1):
    r = [int(bit) for bit in str( bin(v) )[2:].zfill(8)] [::-1]
for v = len(list):
    r = [0] 
w.append(r)
return w
I obtain an empty list

Any help please ?


RE: Two operations in two ranges - DPaul - Jun-22-2020

Hi,

I see some missing indentations starting line 2.
Also, we can't see where and with what you call the def function.

Paul


RE: Two operations in two ranges - salwa17 - Jun-22-2020

Oh sorry :

I indented it correctly:

    def reg_val_list_binary(s):
        r = [0, 0, 0, 254, 179, 0, 2, 0, 0, 0]
        v = []
        w = []
        if v in (0, len(r) - 1):
            r = [int(bit) for bit in str(bin(v))[2:].zfill(8)][::-1]
        if v == len(r):
            r = [0]
        w.append(r)
        return w
The function returns the result of append after conevrting all the values in the for loop


RE: Two operations in two ranges - perfringo - Jun-22-2020

There is parameter s in function which is not used in function body. What and why is that?

if-statements checks:

- #5: "if empty list v in (0, 9)".
- #7: "if empty list v is equal to 10"

In which circumstances these comparisons expected to be true?