To filter the data?

S
Site user since 30.09.2016
Offline
459
#41

If you start from startposta, then there is an array of objects. The problem of solving the problem is sucked from the finger.

on javascript solution:

 a.map (function (item) {if (item.media_category = 'promo') b.push (item)!}); 

The decision on the PHP:

 foreach ($ arr as $ k => $ a) if ($ a-> media_category == 'promo') unset ($ arr [$ k]); 

But the right once to select from the database. And choose a database that can store structured data, rather than any shit.

Отпилю лишнее, прикручу нужное, выправлю кривое. Вытравлю вредителей.
D
Site user since 18.12.2015
Offline
142
#42
timo-71:
Have the JSON, the idea itself is questionable. If it is a file, then yes, your solution is probably the only thing here is how it will solve the problem.

And what's the complexity of the problem? If we have 20 lines, we unpacked them into an array, filtered, and ... that's it. The same array_filter or filter / reduce in the JS. What is the interest? Where streaming reading? The labels sly32 threads written data science, only for them here and does not smell. While that is a junior tasks.

Oh and by the way, the idea is not questionable. Typically, these files remain on Nginx logs that you want to fly to parse and build analytics on them. Or sent for example to synchronize unloading cash balances, it is not uncommon same XML files for a couple of gigs. Or parse XML sitemap for example at the site. A lot of examples.

Разработка и поддержка высоконагруженных проектов.
T7
Site user since 19.09.2018
Offline
31
#43
Danforth:
And what's the complexity of the task

Simple, yes. It can relate to the problem of cost, taking into account the first phrase of the theme:

Sly32:
If anyone has bothered to put plugins

Danforth:
it is not uncommon same XML files for a couple of gigs. Or parse XML sitemap for example at the site.

For XML for PHP even have the funds that do not ship the entire file into memory. Logs - csv row are easy to read.

That if there is to read streaming tools JSON is good as a whole, yes, I agree. "Doubtful," this I mean that I would be in JSON files such data would not be stored

D
Site user since 18.12.2015
Offline
142
#44
timo-71:
It can relate to the problem of cost, taking into account the first phrase of the theme:

Well, it is as if, yes, but on the other hand why then tags in data science - it is not clear)

timo-71:
For XML for PHP even have the funds that do not ship the entire file into memory. Logs - csv row readable .a in general, yes, I agree that if there is to read streaming tools JSON is good. "Doubtful," this I mean that I would be in JSON files such data would not be stored

Well, usually no one important in the JSON or store. Usually, there is a suspended file, which is written the flow of some events, and these events have to read and parse. Option to read the entire file into memory and parse into an array, for obvious reasons, not always possible. What I mean is that if someone seems too easy task, for example, you can apply a bit of skill and a little bit to read the data differently :) After all the data is not always needed, and all at once, as in this example. We do not need to find duplicates, etc.

Let's wait Sly32, posomtrite as it solves the problem

S3
Site user since 29.03.2012
Offline
212
#45

About data science was just a joke)

Python on it will be one row

playbacks = filter (lambda _data: _data [ 'media_category'] not in [ 'promo'], data)

onep
Site user since 30.09.2019
Offline
18
#46

Well, using lambda-expression is used to invoke the function. What's the catch? (If anything, I'm not a programmer)

Show that the more built-in Python functions than in php?

D
Site user since 18.12.2015
Offline
142
#47
Sly32:
playbacks = filter (lambda _data: _data [ 'media_category'] not in [ 'promo'], data)

And the data is in this example? Throw all of the code)

T7
Site user since 19.09.2018
Offline
31
#48
onep:
lambda-expression is used to invoke functions

anonymous

Sly32:
playbacks = filter (lambda _data: _data [ 'media_category'] not in [ 'promo'], data)

Well, in order pedantry

 playbacks = filter (lambda _data: _data [ 'media_category'] not in [ 'promo'], [
    { 'A': 'b'}, 
{ 'B': 'x'},
{ 'Media_category': 'promo'},
])
print (list (playbacks));
 playbacks = filter (lambda _data: _data [ 'media_category'] not in [ 'promo'], [
KeyError: 'media_category' 

 _data.get ([ 'media_category') 

Will help

What dict we are absolutely sure, because noskuel of sampling

---------- Posted 13.06.2020 at 21:34 ----------

And yes, a little longer, but the meaning is

timo-71:
 $ A = array_filter ($ a, function ($ v) {return in_array (_arr ($ v, 'media_category'), [ 'promo', 'xxx']);!}); 

🍿

onep
Site user since 30.09.2019
Offline
18
#49

It is interesting to see an example of sorting an array with an alphanumeric string in Python (not found in the search, in the debate which language is better not to get involved).


[ 'MacBook Air 13.3-inch (2018)', 'MacBook Air 13.3-inch with Retina Display (2018)', 'AirPods',' Apple Pencil ',' Apple Watch ',' MacBook ',' MacBook Air ',' MacBook Pro ',' iPad 9.7 (2018) ',' iPad 10.2 (2019) ',' iPad Air ',' iPad Air (2019) ',' iPad Air 2 ',' iPad 2 ',' iPad 3 '' iPad 4 ',' iPad 9.7 ',' iPad Mini ',' iPad Mini (2019) ',' iPad Mini 2 ',' iPad Mini 3 ',' iPad Mini 4 ',' iPad Pro 9.7 ',' iPad Pro 10.5 ',' iPad Pro 11-inch ',' iPad Pro 11-inch (2020) ',' iPad Pro 12.9 ',' iPad Pro 12.9 (2017) ',' iPad Pro 12.9 (2018) ',' iPad Pro 12.9- inch (2020) ',' iPhone 4 ',' iPhone 4s ',' iPhone 5 ',' iPhone 5c ',' iPhone 5s ',' iPhone 6 ',' iPhone 6 Plus ',' iPhone 6s ',' iPhone 6s Plus', 'iPhone 7', 'iPhone 7 Plus',' iPhone 8 ',' iPhone 8 Plus', 'iPhone 11', 'iPhone 11 Pro', 'iPhone XS 5.8-inch', 'iPhone XS Max', 'iPhone 11 Pro Max', 'iPhone SE', 'iPhone SE 2', 'iPhone X', 'iPhone XR', 'iPod Touch (2019)', 'iPod Touch 5', 'iPod Touch 6']

In php would be written as follows:


uksort ($ data, my_uksort ($ data));
function my_uksort ($ data) {
return function ($ a, $ b) use ($ data) {
return strnatcmp ($ data [$ a], $ data [$ b]);
};
}
T7
Site user since 19.09.2018
Offline
31
#50
onep:
view sample array sorting with alphanumeric

A huge plus python that has everything for all occasions (pip install natsort)

 import natsort 
u = natsort.natsorted (u)

 [ 'AirPods',
 'Apple Pencil', 
'Apple Watch',
'MacBook',
'MacBook Air',
'MacBook Air 13.3-inch (2018)',
'MacBook Air 13.3-inch with Retina Display (2018)',
'MacBook Pro',
'IPad 2'
'IPad 3'
'IPad 4'
'IPad 9.7',
'IPad 9.7 (2018)'
'IPad 10.2 (2019)'
'IPad Air',
'IPad Air 2'
'IPad Air (2019)'
'IPad Mini',
'IPad Mini 2'
'IPad Mini 3'
'IPad Mini 4'
'IPad Mini (2019)',
'IPad Pro 9.7',
'IPad Pro 10.5',
'IPad Pro 11-inch',
'IPad Pro 11-inch (2020)'
'IPad Pro 12.9',
'IPad Pro 12.9 (2017)'
'IPad Pro 12.9 (2018)'
'IPad Pro 12.9-inch (2020)'
'The iPhone 4'
'IPhone 4s',
'The iPhone 5'
'IPhone 5c',
'IPhone 5s',
'The iPhone 6'
'IPhone 6 Plus',
'IPhone 6s',
'IPhone 6s Plus',
'The iPhone 7'
'IPhone 7 Plus',
'The iPhone 8'
'IPhone 8 Plus',
'The iPhone 11'
'IPhone 11 Pro',
'IPhone 11 Pro Max',
'IPhone SE',
'IPhone SE 2'
'IPhone X',
'IPhone XR',
'IPhone XS 5.8-inch',
'IPhone XS Max',
'IPod Touch 5'
'IPod Touch 6'
'IPod Touch (2019)']

To post a new comment, please log in or register