Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help to find a command
#9
Sorry, but it doesn't click... You always append number 1, there is no way to determine in which order flaws occur. You can set tension to min value and find whether there are strengths which are some predefined range.

Something like that:

>>> fiber = [[77, 2], [16, 5], [36, 11], [7, 12], [93, 15], [42, 17], [82, 18], [33, 33], [79, 42], [94, 43]]
>>> tension = min(fiber, key=lambda x: x[0])[0]
>>> tension
7
>>> r = 10                # arbitrary range from breakpoint
>>> [strength + [1] if tension + r >= strength[0] else strength for strength in fiber]
[[77, 2],
 [16, 5, 1],
 [36, 11],
 [7, 12, 1],
 [93, 15],
 [42, 17],
 [82, 18],
 [33, 33],
 [79, 42],
 [94, 43]]
If r = 87 then 1 will be appended to all elements and nobody is any wiser.


Side observation:

- random.randint(0, 100) may include both 0 and 100:

>>> help(random.randint)
Help on method randint in module random:

randint(a, b) method of random.Random instance
    Return random integer in range [a, b], including both end points.
(END)
I believe that fiber cannot break at start and endpoint i.e. at length 0 and 100. In order to avoid surprises it's good to use range like (1, 99) or something.

EDIT: with subjectively better naming:

>>> [[strength, position, 1] if tension + r >= strength else [strength, position] for [strength, position] in fiber]
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


Messages In This Thread
Help to find a command - by andre_fermart - Feb-02-2019, 08:06 AM
RE: Help to find a command - by stullis - Feb-02-2019, 04:15 PM
RE: Help to find a command - by perfringo - Feb-02-2019, 11:47 PM
RE: Help to find a command - by perfringo - Feb-03-2019, 12:51 PM
RE: Help to find a command - by andre_fermart - Feb-04-2019, 08:01 AM
RE: Help to find a command - by perfringo - Feb-04-2019, 09:49 AM
RE: Help to find a command - by andre_fermart - Feb-05-2019, 05:47 AM
RE: Help to find a command - by perfringo - Feb-05-2019, 09:01 AM
RE: Help to find a command - by perfringo - Feb-05-2019, 12:15 PM
RE: Help to find a command - by andre_fermart - Feb-12-2019, 02:34 AM

Forum Jump:

User Panel Messages

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