Python Forum
[split] why can't i create a list of numbers (ints) with random.randrange()
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[split] why can't i create a list of numbers (ints) with random.randrange()
#6
This does not work to remove leading zeros from a binary string.
# probably not good if it starts with zero
if rbs[0] == '0':
    binary = rbs[1:]
else:
    binary = rbs
It works for "011001" but not "0011001". For a more generic solution use lstrip("0"). Use int(binary_string, 2) to convert a binary string to a binary number.
Reply


Messages In This Thread
RE: [split] why can't i create a list of numbers (ints) with random.randrange() - by deanhystad - Oct-23-2022, 04:36 PM
RE: num+1 - by deanhystad - Oct-21-2022, 04:35 PM
RE: num+1 - by astral_travel - Oct-23-2022, 07:17 PM
RE: num+1 - by astral_travel - Oct-21-2022, 06:24 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How do I calculate a ratio from 2 numbers and return an equivalent list of about 1000 Pleiades 8 15,944 Jan-05-2024, 08:30 PM
Last Post: sgrey
  random numbers, randint janeik 2 644 Nov-27-2023, 05:17 PM
Last Post: janeik
  Sample random, unique string pairs from a list without repetitions walterwhite 1 540 Nov-19-2023, 10:07 PM
Last Post: deanhystad
  Delete strings from a list to create a new only number list Dvdscot 8 1,725 May-01-2023, 09:06 PM
Last Post: deanhystad
  find random numbers that are = to the first 2 number of a list. Frankduc 23 3,534 Apr-05-2023, 07:36 PM
Last Post: Frankduc
  List of random numbers astral_travel 17 2,895 Dec-02-2022, 10:37 PM
Last Post: deanhystad
  Remove numbers from a list menator01 4 1,488 Nov-13-2022, 01:27 AM
Last Post: menator01
  Split string using variable found in a list japo85 2 1,385 Jul-11-2022, 08:52 AM
Last Post: japo85
  Divide a number by numbers in a list. Wallen 7 8,232 Feb-12-2022, 01:51 PM
Last Post: deanhystad
  how to easily create a list of already existing item CompleteNewb 15 3,837 Jan-06-2022, 12:48 AM
Last Post: CompleteNewb

Forum Jump:

User Panel Messages

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