Posts: 479
Threads: 86
Joined: Feb 2018
It all depends on what you want to do. The two main path are gaming and web. I actually took gaming then the web path. Either way you should know about most of the python modules, functions, and everything about classes. Then for gaming I suggest pygame. For gaming you should learn techniques to shorten code. This will make games run smoother and the code less messy. For web development, just need to know the basics, but also need to learn html and css. The you can use Flask or Django. I personally like Flask better. Corey Schafer did great tutorial series on both Django and Flask. For learning pygame, I suggest the pygame tutorials here on the forum. Another thing that can help is looking at the pygame threads laying around in the Game Development tab.If you start to enjoy one over the other you can spread out. For example, I spread to C++, javascript (games and web), and Lua (Roblox games).
Posts: 1,950
Threads: 8
Joined: Jun 2018
Jul-01-2019, 07:26 AM
(This post was last modified: Jul-01-2019, 07:26 AM by perfringo.)
My experience is that if more complexity is introduced to data structure then it is good time to return to the drawing board and rethink your approach.
Why there should be additional complexity? Why this structure is required? Source data is list of dictionaries and result is also list of (more complicated) dictionaries. In order to filter out something from this list you have to iterate anyway. Isin't it possible that it is easier to iterate original list instead of creating more complex structure and iterate over it?
Want to have dictionaries from list which are 'good', where n = 1 and without 'm'? List comprehension should be enough:
>>> orig = [{'name': 'John', 'm': 'good', 'n': 1},
... {'name': 'Alina','m': 'good', 'n': 1},
... {'name': 'Olivia', 'm': 'bad', 'n': 2},
... {'name': 'Ruby', 'm': 'bad','n': 2}]
>>> [{k: v for k, v in row.items() if k != 'm'} for row in orig if row['n'] == 1 and row['m'] == 'good']
[{'name': 'John', 'n': 1}, {'name': 'Alina', 'n': 1}] For me it's strange to name source data as 'result'. It may create confusion and confusion may lead to buggy code.
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Posts: 34
Threads: 12
Joined: Apr 2019
It looks great. But I'm not able to understand what's going on here. Anyways, this is only resulting for n = 1 only? - I have not tried it yet.
Posts: 1,950
Threads: 8
Joined: Jun 2018
(Jul-01-2019, 08:23 AM)bhojendra Wrote: It looks great. But I'm not able to understand what's going on here. Anyways, this is only resulting for n = 1 only? - I have not tried it yet.
In spoken language it something like: "give me dictionary except key 'm' for every dictionary in list if dictionary key 'n' has value 1 and dictionary key 'm' has value 'good'". With list comprehension you can filter out whatever you want. The question is what do you want to do with data? Will you query this data constantly (then it can make sense to create new object tailored for queries) or just once-twice?
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Posts: 34
Threads: 12
Joined: Apr 2019
Jul-01-2019, 06:43 PM
(This post was last modified: Jul-01-2019, 06:43 PM by bhojendra.)
As in my initial post, I want the result as like:
result = [
{ // n is 1
"g": [
{
"name": "John",
"n": 1
},
{
"name":"Alina",
"n": 1
}
],
"b": [
{
"name": "...",
"n": 1
},
{
"name": "...",
"n": 1
}
]
},
{ // n is 2
"g": [...],
"b": [...]
},
{ // n is 3
// ...
}
] And I think I understood one liner syntax. I will try this.
Posts: 1,950
Threads: 8
Joined: Jun 2018
Jul-01-2019, 08:45 PM
(This post was last modified: Jul-01-2019, 08:45 PM by perfringo.)
(Jul-01-2019, 06:43 PM)bhojendra Wrote: As in my initial post, I want the result as like:
I asked why you want result like that? What are the benefits of new structure over old one?
old = [{'name': 'John', 'm': 'good', 'n': 1},
{'name': 'Alina','m': 'good', 'n': 1},
{'name': 'Olivia', 'm': 'bad', 'n': 2},
{'name': 'Ruby', 'm': 'bad','n': 2}]
new = [{'g': [{'name': 'John', 'n': 1}, {'name': 'Alina', 'n': 1}]},
{'b': [{'name': 'Olivia','n': 2},{'name': 'Ruby','n': 2}]}] Old list dictionaries have exactly the same structure, new list dictionaries not (some have key 'g', some key 'b' and some probably both). You must be extra careful to not run into KeyError while accessing data.
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
|