Skip to main content

All Questions

-4 votes
3 answers
394 views

Python comprehension with different number of elements

The general problem I have a case where I'm generating an element comprehension with a different cardinality to the input source. This cardinality should not be a multiple of the original (data-driven)...
Ricardo's user avatar
  • 821
-1 votes
1 answer
95 views

Making dictionary more functional

how can i change the code, to make it more functional (change the for loop for the same result only to make it shorter in 2 sentences)? def get_language_from_text(): """ Simply ...
warrior.0779's user avatar
1 vote
2 answers
84 views

How to group lists with common elements into dict using functional approach in python?

I am trying to aggregate lists into dict. First column can be treated as id and second column as some random element. I want all elements assigned to the same id to be grouped in a list under that id. ...
hdw3's user avatar
  • 951
1 vote
1 answer
223 views

Convert a list comprehension to functional programming

I have a list of dictionaries lst = [{'a': (1, 2, 3), 'b': (2, 3)}, {'c': (3, 6), 'd': (4, 8), 'e': (5, 10)}, {'d': (6, 12), 'e': (7, 14)}] For each key in each dictionary, I want to ...
user avatar
0 votes
0 answers
25 views

Using functionality paradigms in reduce nested lists [duplicate]

I have the following problem, transform the structure below [[1], [2,3,4,5,6], [7,8,9]] by getting items from nested lists, as a result [1,2,3,4,5,6,7,8,9] The simplest implementation can be written ...
Costy's user avatar
  • 165
1 vote
3 answers
224 views

Functional Programming : Creating a dictionary whilst merging values of duplicate keys into a list

Say I have the following list values = ["Cat" , "Mat" , "Jack", "Cord"] I want to implement it using a functional approach How can I create an alphabetical ...
Scb's user avatar
  • 337
0 votes
2 answers
65 views

Delete Key by its value in Python Dictionary

I have a dictionary in which , I want to remove the key whose name start from S, which is "person_3". My_Dict = { "person_1": {"name": 'John', "age"...
Abdul Wahab's user avatar
-2 votes
4 answers
1k views

Shortest way to update a list of dictionaries in one line

Say I have a variable, people, which is a list of person dictionaries. I want to add a serial number id to each dictionary in the list. I could do this: people = [{'name':'jo'},{'name':'rob'},{'name':'...
Rap's user avatar
  • 7,292
3 votes
2 answers
3k views

Python: Remove item from dictionary in functional way

I've been programming in Python for quite a while now. I've always wondered, is there a way to remove an item from a dictionary and return the newly created dictionary? Basically removing an item from ...
Omniscient Potato's user avatar
0 votes
2 answers
49 views

Several identical dictionaries component mean

I have several Python3 dictionaries with the same identical structure, mapping string labels to real values. For example, for 4 entries, the data set could look like: {"a": 1.2, "b&...
Daniel Pop's user avatar
0 votes
2 answers
413 views

Using reduce() to get frequency of every character pair/triple in a string?

I am supposed to complete this task in a functional manner, so no loops of any sort. I already completed the task for finding the frequency of single characters. My code looks like this: char_freq =...
kastaplastislife's user avatar
1 vote
2 answers
382 views

reduce list of functions with keyword argument on dictionary in python

:) I want to build a very tiny functional pipeline in my code to reduce a bunch of functions on a single dictionary. Every function does 1 thing, but on different keys, here's a simplified example: ...
Tytire Recubans's user avatar
1 vote
1 answer
37 views

how to take spesific value in list dictionary

here's my whole code a = str(input("parent1 :")) b = str(input("parent2 :")) p = {'rose':'R_P_', 'pea':'rrP_'} print(p[a] +" : "+p[b]) f = [] print('gamet 1 : ' + p[a][0]+p[a][2]) print('gamet 2 : '...
Apostrophes's user avatar
0 votes
2 answers
125 views

reduce functions on a dictionary python

This might be somehow of a trivial question, but I have a dictionary on which I would like to apply some 10 functions to modify its content. I think this would be a good case for reduce but I cannot ...
Tytire Recubans's user avatar
2 votes
4 answers
755 views

Python: get the corresponding key from value

def get_nearest_less_element(d, k): return (min(value for value in map(float, d.values()) if value >= k)) So, d is a dict() and k is float, this function returns me the correct value, but can I ...
MrRobot9's user avatar
  • 2,704

15 30 50 per page
1
2 3 4 5