Not Yet Answered # slicing help

richieking 44 Thisisnotanid ### Code I don't want repeated

0

Slice what? which part???? can you please provide more info and any code you have .

:)

0

Let's say you have the array as a list. Here's a possible solution:

```
# This solution's assuming you have values for bounds that match values in the range you have.
T = range(0, 101) # Arbitrary list of temperatures.
T1 = 5 # Arbitrary first lower bound.
T2 = 35 # Arbitrary first upper bound.
T3 = 50 # Arbitrary second lower bound
T4 = 75 # Arbitrary second upper bound
# Slicing is as follows:
T1s = T[T.index(T1): T.index(T2) + 1] # First sub-list containing temperatures in the first range, inclusive.
T2s = T[T.index(T3): T.index(T4) + 1] # Second sub-list containing temperatures in the second range, inclusive.
# The following solution's assuming you don't have values for bounds that match values in the range you have, but you still want temperatures in that range. It uses the same naming convention as above.
T = range(0, 101) # Arbitrary list of temperatures.
T1 = 5 # Arbitrary first lower bound.
T2 = 35 # Arbitrary first upper bound.
T3 = 50 # Arbitrary second lower bound
T4 = 75 # Arbitrary second upper bound
# But now let's assume T1, T2, T3, and T4 aren't in T. So:
x = T[0]
while x < T1:
for m in T:
if m > T1:
T1 = m
x = m
y = T[len(T) - 1]
while y > T2:
for m in T:
if m < T2:
T2 = m
y = m
# The process will be the same for T3 and T4. Then:
T1s = T[T.index(T1): T.index(T2) + 1] # First sub-list containing temperatures in the first range, inclusive.
T2s = T[T.index(T3): T.index(T4) + 1] # Second sub-list containing temperatures in the second range, inclusive.
```

This article has been dead for over six months. Start a new discussion instead.

Recommended Articles

Hi,

I want to create a Alternate Coloring in MsFlexGrid that using the Visual Basic Programming.

Here I attach a source code :

MsFlexGrid I give name : Flex

If Wt <= RsParts.Fields!Lowerlimit Then

```
'***********************************************************
'2. Section for create Color at 1 Column under REMARK
Dim lngRow As Long
Dim ...
```

How do I make a line of code that would go back to a part of a program without making it a loop?

For example

some line for later to come back (line 2)

$$$code I want to repeat$$$

jump back to line 2

Hi,

I am facing an issue in string to const char pointer conversion. I am doing stuff in the fun() but here i am just giving my example. Here it the code:

```
// Helper function
string fun() {
string abc = "Daniweb";
// print here #1
return abc;
}
// ...
```