list manipulation – Replacement of sublists by criteria or interpolation for a smooth curve

Suppose we have the following list (very small, can be copied directly into a notebook)

{
{1.25, 0},
{1.3, 0.125},
{1.4, 0.175},
{1.5, 0.225},
{1.6, 0.275}, {1.7, 0.275},
{1.8, 0.325},
{1.9, 0.375}, {2., 0.375}, {2.1, 0.375},
{2.2, 0.425}, {2.3, 0.425},
{2.4, 0.475}, {2.5, 0.475}, {2.6, 0.475}, {2.7, 0.475},
{2.8, 0.525}, {2.9, 0.525}, {3., 0.525},
{3.1, 0.575}, {3.2, 0.575}, {3.3, 0.575}, {3.4, 0.575}, {3.5, 0.575},
{3.6, 0.625}, {3.7, 0.625}, {3.8, 0.625}, {3.9, 0.625}, {4., 0.625},
{4.1, 0.675}, {4.2, 0.675}, {4.3, 0.675}, {4.4, 0.675}, {4.5, 0.675}, {4.6, 0.675}, {4.7, 0.675},
...}

The special feature of the list is some adjacent sublists with the same 2nd elements and 1st continuous element, as the line breaks emphasize. By plotting it, we can see that the aforementioned feature causes the dots to be aligned horizontally in a step-by-step manner.

ListPlot(data, Frame -> True, PlotRange -> {{0, 10}, {0, 1}}, ImageSize -> 400, PlotStyle -> {Red, Thick})

enter description of image here

What I want is a smooth "fit" curve instead of a discrete point plot. To this end, I have tried Interpolation, but it turns out that the increase InterpolationOrder is of no help. Btw, adding an option to Method -> "Hermite" or Method -> "Spline" is useless either. I also tried Fit(data, {1, x, x^2, x^3}, x), which turns out to be even worse.

interpdata = Interpolation(data, InterpolationOrder -> 10);
Plot(interpdata(x), {x, data((1, 1)), data((-1, 1))}, Frame -> True, PlotRange -> All, ImageSize -> 400, PlotStyle -> {Red, Thick})

enter description of image here

So i want to manipulate the original data by replacing the adjacent sublists with the same 2nd element using a procedure like this:

Check the length of the adjacent sublists with the same 2nd element and use the average value of their 1st elements as the 1st element of the new sublist, then replace these sublists with the resulting sublist, that’s -to say, {mean of 1st elem, the same 2nd elem}. For example,

{1.6, 0.275}, {1.7, 0.275} => {1.65, 0.275},

{1.9, 0.375}, {2., 0.375}, {2.1, 0.375} => {2, 0.375}

{2.4, 0.475}, {2.5, 0.475}, {2.6, 0.475}, {2.7, 0.475} => {2.55,0.475}

I guess it can be done with SequenceSplit and the new list should give me a reasonable curve. But i'm having trouble using SequenceSplit in that case. Could someone help me? It will be great if some interpolation method can be compared to the plot of the new list. Thank you!

list manipulation – Adding different numbers to sublists

This problem concerns Prepend 0 to the sublists
I have the list

t1 = Table[m = n + IntegerReverse[n]; n = m, {n, 3}, {i, 1, 4}]

giving

{{2, 4, 8, 16}, {4, 8, 16, 77}, {6, 12, 33, 66}}

But I want to start with the first value n so I should get

{{1, 2, 4, 8, 16}, {2, 4, 8, 16, 77}, {3, 6, 12, 33, 66}}

This can be done by

Prepend[#, #[[1]]/2] & /@ t1

But it's cheating awkwardly. How can I do it correctly or with the Table command? I tried Hold and Prepend inside Table but got nothing.

List of overlapping partitions in N sublists as evenly as possible

There are similar questions here, I haven't seen one where there is an overlap.

The requirements:

  • The result must be N sublists with the specified overlap.
  • There should be no deleted items
  • Sublists must be as equal in length as possible, that is, there must be a minimum number of different sublist lengths and the difference between sublist lengths must be minimized.

For example, given Range[10] and the overlap of 1 would be the output for different numbers of sublists:

N   Output
1   {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}}
2   {{1, 2, 3, 4, 5, 6}, {6, 7, 8, 9, 10}}
3   {{1, 2, 3, 4}, {4, 5, 6, 7}, {7, 8, 9, 10}}
4   {{1, 2, 3, 4}, {4, 5, 6}, {6, 7, 8}, {8, 9, 10}}
5   {{1, 2, 3}, {3, 4, 5}, {5, 6, 7}, {7, 8, 9}, {9, 10}}
6   {{1, 2, 3}, {3, 4, 5}, {5, 6, 7}, {7, 8}, {8, 9}, {9, 10}}
7   {{1, 2, 3}, {3, 4, 5}, {5, 6}, {6, 7}, {7, 8}, {8, 9}, {9, 10}}
8   {{1, 2, 3}, {3, 4}, {4, 5}, {5, 6}, {6, 7}, {7, 8}, {8, 9}, {9, 10}}
9   {{1, 2}, {2, 3}, {3, 4}, {4, 5}, {5, 6}, {6, 7}, {7, 8}, {8, 9}, {9, 10}}

Note: Above is a handmade example and it is not mandatory that the splitting be done as in the example above. For example, for N = 4, one of the following would be valid:

{{1, 2, 3, 4}, {4, 5, 6}, {6, 7, 8}, {8, 9, 10}}
{{1, 2, 3}, {3, 4, 5}, {5, 6, 7}, {7, 8, 9, 10}}

List manipulation: conditional result based on variable length sub-lists, second part

This is a consequence of this question.

Suppose I have the following definitions:

eqexp = {a, b, c, d};
eqval = {e, f, g, h};
signval = {{}, {1}, {-1}, {1, -1}};
criteria = {{}, {i}, {j}, {k, l}};

As before, I want Signval to determine whether the eqexp component is greater or less than the eqval component. But now, I have an additional list (criteria) that has the same structure as signval. I want the value of the corresponding criterion to be equal to zero as well, then the resulting inequalities combine with a gold. So the desired result would be:

{False, b> f && i == 0, c < g && j == 0, 
 (d > h && k == 0) || (d <h && l == 0)}

The previous answers (without the criterion component) were cleverly using a replacement rule on signval. I do not see how to do the same thing here. No suggestion?

sierra – How to create numbered sub-lists in the Mail application?

Is it possible to create nested numbered lists in the MacOS mail client? -for example.:

1. Foo
1.1. Foo is cool
1.2. Foo is awesome
2. Bar
2.1. Bar is not so cool
2.2. The bar is not terrible

I have tried but all attempts so far have failed. This is very basic. There must be a way.

I use MacOS Sierra (10.12.6) and Mail version 10.3 (3273).

python – selects the maximum and minimum values ​​in a list with sublists

Hello, I have the following arrangement and I want to select the maximum and minimum value of this arrangement. How can I do it?

ytra01 =[array([1.18182126307657e-125, -0.0119506376551417, -0.0238653670087153,
-0.0357093641553568, -0.0474489881673787, -0.0590517810947708,
-0.0704864679651997, -0.0817229567840087, -0.0927323385342183,
-0.103486887176526, -0.113960059649305, -0.124126495868608,
-0.133962018728162, -0.143443634099373, -0.152549530831321,
-0.161259080750767, -0.169552838662145, -0.177412542347568,
-0.184821112566827, -0.191762653057386, -0.198222450534390,
-0.204186974690659, -0.209643878196690, -0.214581996700658,
-0.218991348828412, -0.222863136183482, -0.226189743347072,
-0.228964737878063, -0.231182870313016, -0.232840074166164,
-0.233933465929421, -0.234461345072376, -0.234423194042295,
-0.233819678264123, -0.232652646140478, -0.230925129051658,
-0.228641341355637, -0.225806680388066, -0.222427726462272,
-0.218512242869262, -0.214069175877715, -0.209108654733991,
-0.203641991662125, -0.197681681863830, -0.191241403518495,
-0.184336017783187, -0.176981568792647, -0.169195283659298,
-0.160995572473234, -0.152402028302231, -0.143435427191739,
-0.134117728164886, -0.124472073222477, -0.114522787342993,
-0.104295378482593, -0.0938165375751110, -0.0831141385320608,
-0.0722172382426312, -0.0611560765736884, -0.0499620763697752,
-0.0386678434531117, -0.0273071666235948, -0.0159150176587985,
-0.00452755131397313, 0.00681789467795345, 0.0180827996063767,
0.0292274597830153, 0.0402109885419106, 0.0509913162394275,
0.0615251902542539, 0.0717681749874005, 0.0816746518622012,
0.0911978193243132, 0.100289692841717, 0.108901104904715,
0.116981705025934, 0.124479959740323, 0.131343152605155,
0.137517384200026, 0.142947572126853, 0.147577451009879,
0.151349572495669, 0.154205305253110, 0.156084834973414,
0.156927164370114, 0.156670113179067, 0.155250318158455,
0.152603233088780, 0.148663128772868, 0.143363093035869,
0.136635030725257, 0.128409663710825, 0.118616530884694,
0.107183988161304, 0.0940392084774217, 0.0791081817921341,
0.0623157150868521, 0.0435854323653106, 0.0228397746535661,
-3.25260651745651e-16], dtype = object),
board ([1.18182126307657e-125, -0.0249772674435424, -0.0519907845042112,
-0.0809050263018950, -0.111586833911836, -0.143905414364630,
-0.177732340646228, -0.212941551697932, -0.249409352416401,
-0.287014413653646, -0.325637772217032, -0.365162830869278,
-0.405475358328457, -0.446463489267996, -0.488017724316676,
-0.530030930058630, -0.572398339033347, -0.615017549735669,
-0.657788526615792, -0.700613600079266, -0.743397466486994,
-0.786047188155233, -0.828472193355595, -0.870584276315045,
-0.912297597215901, -0.953528682195836, -0.994196423347878,
-1.03422207872041, -1.07352927231715, -1.11204399409721,
-1.14969459997501, -1.18641181182037, -1.22212871745841,
-1.25678077066966, -1.29030579118996, -1.32264396471053,
-1.35373784287793, -1.38353234329408, -1.41197474951625,
-1.43901471105707, -1.46460424338452, -1.48869772792194,
-1.51125191204800, -1.53222590909676, -1.55158119835760,
-1.56928162507529, -1.58529340044991, -1.59958510163693,
-1.61212767174716, -1.62289441984676, -1.63186102095725,
-1.63900551605550, -1.64430831207375, -1.64775218189956,
-1.64932226437588, -1.64900606430099, -1.64679345242853,
-1.64267666546750, -1.63665030608224, -1.62871134289246,
-1.61885911047322, -1.60709530935493, -1.59342400602335,
-1.57785163291959, -1.56038698844014, -1.54104123693682,
-1.51982790871680, -1.49676290004262, -1.47186447313217,
-1.44515325615869, -1.41665224325077, -1.38638679449237,
-1.35438463592278, -1.32067585953667, -1.28529292328403,
-1.24827065107025, -1.20964623275603, -1.16945922415744,
-1.12775154704592, -1.08456748914824, -1.03995370414653,
-0.993959211678288, -0.946635397336348, -0.898036012668906,
-0.848217175179511, -0.797237368327065, -0.745157441525825,
-0.692040610145400, -0.637952455510755, -0.582960924902207,
-0.527136331555429, -0.470551354661445, -0.413281039366636,
-0.355402796772732, -0.296996403936824, -0.238144003871350,
-0.178930105544105, -0.119441583878238, -0.0597676797522508,
-6.50521303491303e-16], type = object)]I should throw the values ​​0,1569 (maximum) and -1,649 minimum, but the correct values ​​are not indicated

float (max (ytra01, key = lambda x: x[2])[0])
float (min (ytra01, key = lambda x: x[2])[0])
I appreciate your help

manipulation list – Extraction of sublists containing similar elements

Let's say I have a list containing sub-lists of different sizes of structured string pairs like this

{{{"A", "B"}, {"C", "D"}}, {{"E", "D"}, {"G", "B"}}, {{"H"} , "B"}}, {{"I", "B"}}}

where the first and second sublists each contain two pairs of strings and the third and fourth sublists each contain a pair of strings.

I want to delete all the channel pairs for which the second channel is not in each sub-list. For example, there are pairs of strings in each sublist where the second string of the pair is "B". So, I just want to keep those pairs of strings. The final list should look like this

{{{"A", "B"}}, {{"G", "B"}}, {{"H", "B}}}, {{" I "," B "}}

Although each of the first two sub-lists contains a pair of strings containing a "D" in the second element, they must be deleted because there are no string pairs containing "D" in the second element pairs of strings. in the third and fourth sub-lists.

I would like this function to work regardless of the number of sub-lists and the number of items contained in these sub-lists. I know how to do this if the list has been completely flattened, but it is not the case here. It is not necessary that this process be effective. Anything that can produce these results would be useful. Ideas?

python3 – I've developed an iterative code to generate sub-lists but I want a recursive type code. How can I do it, can I provide the code?

                def sub_lists (list1):
sub list = [[]]for i in the range (len (list1) + 1):
for j in the range (i + 1, len (list1) + 1):
sub = list1[i:j] 
                sublist.append (sub)
back sub-list
if __name __ == "__ main__":
l1 = [1, 2, 3, 4] 
    print (sublists (l1)) 

I've tried this iterative code, but I can not get recursion code because it can help me get the recursive code

google docs – How can we attribute mixed list styles to sub-lists of the same level?

It seems that if you change the list style (for example, numbered in Roman numerals or in square) in Google Docs for a list of a certain level, the other sub-lists of the same level are also modified. For example, you can not have:

  1. Search
    1. thimbles
    2. care
  2. Continue

changing the first sub-list to a numbered list also changes the second, and changing the second sub-list to a smart list also changes the first. What are the possible ways to have sub-lists with different styles, changing the type of list and the marker?

python – Attempt to add conditional tuples from a list of tuples to sub-lists of tuples in a dictionary

I do not know how to reach what I want, so I post here.

I have a dictionary where each value is a list of tuples (I'll call it dict1), which I cross against a list of tuples (I'll call it list1). The idea is to add any tuple listed in list1 to each sub-list of dict1's that it does not already exist in the sub-list in the form (tuple, 0).

Here is what it looks like:

dict1 = {2011: [('Debt collection', 5572),
                ('Mortgage', 4483),
                ('Student loan', 431)],
2012: [('Consumer Loan', 480),
                ('Student loan', 1632),
                ('Medical loan', 1632),
                ('Prepaid card', 83)]}

list1 = [('Debt collection', 5572),
         ('Mortgage', 4483),
         ('Credit reporting', 3230),
         ('Checking or savings account', 2068),
         ('Student loan', 1632),
         ('Credit card or prepaid card', 1577),
         ('Bank account or service', 1327),
         ('Credit card', 1156),
         ('Consumer Loan', 480)]

I want my code to check if the first part of each tuple of list1 exists in each list of values ​​of dict1, and if it does not, add it to each list of values ​​in the form ( tuple, 0):

dict1 = {2011: [('Debt collection', 5572),
                ('Mortgage', 4483),
                ('Student loan', 431),
                ('Credit reporting', 0),
                ('Checking or savings account', 0),
                ('Credit card or prepaid card', 0),
                ('Bank account or service', 0),
                ('Credit card', 0),
                ('Consumer Loan', 0)],
2012: [('Consumer Loan', 480),
                ('Student loan', 1632),
                ('Medical loan', 1632),
                ('Prepaid card', 83),
                ('Debt collection', 0),
                ('Mortgage', 0),
                ('Credit reporting', 0),
                ('Checking or savings account', 0),
                ('Credit card or prepaid card', 0),
                ('Bank account or service', 0),
                ('Credit card', 0)]}

I first tried to extract the first part of each tuple from list1 as a separate list:

    available = [tpl[0] for tpl in list1]

Then I try the following:

    dict1.update (v.extend (tuple ((tpl[0], 0)) for tpl in v 
for k, v in dict1.items () 
if tpl[0] not available))

I receive the following error:

TypeError Traceback (last call passed)
 in ()
----> 1 dict1.update (v.extend (list (tuple ((tpl)[0], 0)) for tpl in v for k, v in dict1.items ()
if tpl[0] not available)))

 in (.0)
----> 1 dict1.update (v.extend (list (tuple ((tpl)[0], 0)) for tpl in v for k, v in dict1.items ()
if tpl[0] not available)))

TypeError: The object's generator & # 39; is not recordable

I was looking for but I did not find anything that really answered a similar case. I suppose I must use .update for dict1 as well as .extend on each list of values ​​(v) in order to treat each list individually.