Python Forum
Two operations in two ranges
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Two operations in two ranges
#1
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 ?
Reply
#2
Hi,

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

Paul
It is more important to do the right thing, than to do the thing right.(P.Drucker)
Better is the enemy of good. (Montesquieu) = French version for 'kiss'.
Reply
#3
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
Reply
#4
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?
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Replicate Excel operations with Python Lumberjack 3 912 May-10-2022, 01:44 AM
Last Post: Lumberjack
  Program demonstrates operations of bitwise operators without using bitwise operations ShawnYang 2 1,207 Aug-18-2021, 03:06 PM
Last Post: deanhystad
  Dictionary with ranges that have a float step value Irv1n 2 1,536 Apr-21-2021, 09:04 PM
Last Post: Yoriz
  Random Choice Operations Souls99 6 2,003 Jul-31-2020, 10:37 PM
Last Post: Souls99
  Create bot to automate operations in IQ Option JonatasCavalini 0 6,904 Jul-19-2020, 02:23 AM
Last Post: JonatasCavalini
  How to avoid slow cursor operations? sevensixtwo 0 1,392 Oct-11-2019, 02:23 PM
Last Post: sevensixtwo
  Operations on indexed variables in loop Fibulavie 1 1,479 Aug-14-2019, 06:07 AM
Last Post: fishhook
  iterating a list of ranges Skaperen 1 1,494 May-22-2019, 07:44 AM
Last Post: Gribouillis
  Subnet Mask Ranges ab52 0 1,396 Mar-11-2019, 10:39 AM
Last Post: ab52
  Confused by order of operations ward 4 1,932 Jan-22-2019, 08:53 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020