Создавай тему, почему бы и нет
Create a theme, why not?
data = [ {'id': 0, 'media_category': 'clip'}, {'id': 1, 'media_category': 'promo'}, {'id': 2, 'media_category': 'promo'}, {'id': 3, 'meda_category': 'promo'}, {'id': 4, 'media_category': 'clip'}]def filter_data(data): return filter(lambda _data: _data.get('media_category') not in ['promo'], data) result = filter_data(data)for item in result: print(item)
собственно, сам код - строки 9-10, остальное - чтобы проверить в любой питоновской консоли. В рамках задачи мне потребовалось вставить 2 строки в существующий код - проверка на ключ, что нужно фильтровать и сама фильтрация.
Про скорость - понятно что го будет быстрее, но все это компилируется в сpython в реальности, там уже несильно важно.
Дв а принципе, я ничего не имею против кода на пхп, это не тема для срача)
Спасибо всем за участие, будете у нас в Минске - с удовольствием пересекусь за пивом. Думаю тема исчерпана
data = [ { 'Id': 0, 'media_category': 'clip'}, { 'Id': 1, 'media_category': 'promo'}, { 'Id': 2, 'media_category': 'promo'}, { 'Id': 3, 'meda_category': 'promo'}, { 'Id': 4, 'media_category': 'clip'}] def filter_data (data): return filter (lambda _data: _data.get ( 'media_category') not in [ 'promo'], data) result = filter_data (data) for item in result: print (item)
in fact, the code itself - lines 9-10, the rest - to check any pitonovskoj console. As part of the task, I need to insert 2 lines to the existing code - a key check, you need to filter and filtering itself.
About speed - it is clear that the first will be faster, but it is compiled into spython in reality, there has not much important.
Dve and principle, I have nothing against the code on php, this is not a topic for sracha)
Thank you all for your participation, we will have in Minsk - happy Crossing for a beer. I think the topic is exhausted
Проверь, если есть сомнения)
Check, if in doubt)
Буду только рад за тебя, если получится. Просто пока что все, кроме тебя видят, что ты занимаешься ерундой. Твои решения ничего не дают ни в плане простоты, скорости, универсальности. да ты и сам не понимаешь, к чему стремишься)
I will be glad for you, if possible. Just as long as everything, but you can see that you are doing nonsense. Your solutions do not give any terms of simplicity, speed, versatility. but you yourself do not know, something to strive for)
Бесспорно, лучше. Но есть бизнес-логика и в ее рамках не всегда получается
Ну вот пример пример в данном случае, попробую обьяснить, почему это невыгодно делать на уровне БД. Запрос в постгресс делается 1 раз, потом данные храняться в редисе и в разных кейсах мне нужно получать разные итоговые данные. Задача - лишь один из них. Мне не нужно каждый раз стучаться в БД, я работаю с уже полученной коллекцией.
Поэтому и нужно решать средствами языка а не рассуждать - как еще это можно сделать.
Мне неинтересно что есть в гугле - мне было интересно предложить народу поиграться с чем-то больше чем настраивать плагины. Тот кто умеет мыслить - включился и предложил решения, болтуны начали рассуждать...
по итогу - код на питоне - самый короткий и читабельный)
Тем кто отвечал по существу - спасибо за интересную дискуссию)---------- Добавлено 14.06.2020 в 13:24 ----------
Важная, но я не говорил что сложная или для сеньоров - так, развлечься. Я например, потратил гораздо больше времени на написание тестов чем на саму задачу)
Undoubtedly, the better. But there is business logic, and within it is not always possible
Well, that's an example of an example in this case, I will try to explain why it is not profitable to do at the database level. Request to postgress done 1 time, then the data stored in the radishes and various case studies I need to get different totals. The task - only one of them. I do not need every time to knock in the database, I am working with the already received collection.
Therefore it is necessary to solve by means of language and not talk - how else to do it.
I'm not interested in what is in Google - it was interesting to offer people to play with something more than customize plugins. Anyone who knows how to think - was involved and suggested solutions, babblers began to reason ...
at the end - the code in Python - the shortest and most readable)
Those who replied in essence - thanks for an interesting discussion) ---------- Posted 14.06.2020 at 13:24 ----------
Important, but I did not say that the complex or for seniors - so fun. I like to have spent more time writing tests than on the task itself)