How to get a specific value from a dictionary within a list - dictionary

I am trying to find all the keys that have the world 'symbol' and print out their respective values in one go. The data set given is wrapped in a list as well.
[{'symbol': 'BTCUSDT', 'initialMargin': '2.68109529', 'maintMargin': '0.13405476', 'unrealizedProfit': '-0.07952355', 'positionInitialMargin': '2.68109529', 'openOrderInitialMargin': '0', 'leverage': '5', 'isolated': False, 'entryPrice': '0.899', 'maxNotional': '250000', 'positionSide': 'BOTH', 'positionAmt': '15.0', 'notional': '13.40547645', 'isolatedWallet': '0', 'updateTime': '1676641281047', 'bidNotional': '0', 'askNotional': '0'}, {'symbol': 'EOSUSDT', 'initialMargin': '3.22845093', 'maintMargin': '0.08071127', 'unrealizedProfit': '-0.06225465', 'positionInitialMargin': '3.22845093', 'openOrderInitialMargin': '0', 'leverage': '5', 'isolated': False, 'entryPrice': '1.072', 'maxNotional': '2000000', 'positionSide': 'BOTH', 'positionAmt': '-15.0', 'notional': '-16.14225465', 'isolatedWallet': '0', 'updateTime': '1676641497608', 'bidNotional': '0', 'askNotional': '0'}]
So I want to pull both the 'BTCUSDT' and 'EOSUSDT' by finding the word 'symbol'
I've tried everything to get this to work.

Related

Extracting information from string and creating new variable

I have a column with big character strings like this:
"[{'tipoTeste': 'RT-PCR', 'estadoTeste': 'Concluído',
'dataColetaTeste': {'__type': 'Date', 'iso': '2021-12-30T03:00:00.000Z'},
'resultadoTeste': 'Detectável', 'loteTeste': None,
'fabricanteTeste': None, 'codigoTipoTeste': '1', 'codigoEstadoTeste': '3',
'codigoResultadoTeste': '1', 'codigoFabricanteTeste': None}]"
And i want to create another variable called Date with the date information inside this huge string, in this case is 2021-12-30
Im not managing to grep this date information for all rows....
This would work:
library(stringr)
str_extract_all(str, "[0-9]{4}-[0-9]{2}-[0-9]{2}")
[[1]]
[1] "2021-12-30"
We could use parse_date directly on the string
library(parsedate)
> as.Date(parse_date(str1))
[1] "2021-12-30"
data
str1 <- "[{'tipoTeste': 'RT-PCR', 'estadoTeste': 'Concluído',
'dataColetaTeste': {'__type': 'Date', 'iso': '2021-12-30T03:00:00.000Z'},
'resultadoTeste': 'Detectável', 'loteTeste': None,
'fabricanteTeste': None, 'codigoTipoTeste': '1', 'codigoEstadoTeste': '3',
'codigoResultadoTeste': '1', 'codigoFabricanteTeste': None}]"

Tinkerpop Select multiple neighbours grouped by the vertex they are neighbour with range step

I want to select all l labelled vertices along with their t,n labelled vertices grouped by their neighbours. Also I want to apply a limit on the length of the neighbours. For ex for neighbour limit = 2 something like below should be output.
[
{"l1",{[t1,t2]}, {}},
{"l2",{[t3]}, {[n1]}},
{"l3",{[]}, {[n2,n3]}}
]
For ex for neighbour limit = 1 something like below should be output.
[
{"l1",{[t1,t2]}, {}},
{"l2",{[t3]}, {[n1]}},
{"l3",{[]}, {[n2]}}
]
grelify link https://gremlify.com/xun4v83y54/2
g.addV('Vertex').as('1').property(single, 'name', 'l1').property(single, 'label', 'l').
addV('Vertex').as('2').property(single, 'name', 'l2').property(single, 'label', 'l').
addV('Vertex').as('3').property(single, 'name', 'l3').property(single, 'label', 'l').
addV('Tag').as('4').property(single, 'name', 't1').property(single, 'label', 't').
addV('Tag').as('5').property(single, 'name', 't2').property(single, 'label', 't').
addV('Tag').as('6').property(single, 'name', 't3').property(single, 'label', 't').
addV('neighbour1').as('7').property(single, 'name', 'n1').property(single, 'label', 'n').
addV('neighbour2').as('8').property(single, 'name', 'n2').property(single, 'label', 'n').
addV('neighbour3').as('9').property(single, 'name', 'n3').property(single, 'label', 'n').
addE('connected').from('1').to('4').
addE('connected').from('1').to('5').
addE('connected').from('2').to('6').
addE('connected').from('2').to('7').
addE('connected').from('3').to('8')
addE('connected').from('3').to('9')
For this output you can try doing something like this:
g.V().hasLabel('l').
group().by('name').
by(out('connected').fold()
project('t', 'n').
by(unfold().hasLabel('t').limit(1).values('name').fold()).
by(unfold().hasLabel('n').limit(1).values('name').fold())
.unfold().select(values).fold())
You can change the limit to be the max number of neighbors you want from each type.
example: https://gremlify.com/ecw6j2ajh5p

How to get the each value of documents from a collection in a seprate list according to the document id in flutter

For Example In a Collection there are 10 or more Documents I want to create the list of that collection according to the DocumentsId and the list contains only values not keys.
Document 1-->
'Num1':'1',
'Num2':'2',
'Num3': '3',
'Num4': '4',
'Num5': '5',
'Num6': '6',
'Num7': '7',
'Num8': '8',
'Num9': '9',
'Num10': '10',
Document 2-->
'Num1':'1',
'Num2':'2',
'Num3': '3',
'Num4': '4',
'Num5': '5',
'Num6': '6',
'Num7': '7',
'Num8': '8',
'Num9': '9',
'Num10': '10',
The list be like this for every Document
List document1 = [1,2,3,4,5,6,7,8,9,10]
List document2 = [11,12,13,14,15,16,17,18,19,20]
And the every list name is the documentid
Assuming the 'Collection' is a simple map object you can do:
Map temp= { 'Num1':'1',
'Num2':'2',
'Num3': '3',
'Num4': '4',
'Num5': '5',
'Num6': '6',
'Num7': '7',
'Num8': '8',
'Num9': '9',
'Num10': '10',};
var newList=temp.values.toList();
If it is a custom object you can use the map method :
myobjectList.map((object)=>object.id).toList();
It will iterate all the elements in the collection and 'map' every one to the property you need.
EDIT:
Dinamically you cannot change a variable name, but you can change a variable attributes.
What you wish can be achieved as:
List<List<int>> documents;
//access each document by its index
List document1 = [1,2,3,4,5,6,7,8,9,10]
documents[0]//would be equal to accessing document1
OR use a map:
Map map={document.name:[1,2,3,4,5]};
map['document2']=[6,7,8,9,10];

Too many functions, how to reduce it?

[EDIT]
I am writing codes with SQLite in AutoHotkey(minor Windows language).
But, I have problem with UDF(User Define Function) in the middle of it.
So, I can not use RegExp..OMG. Therefore, I am having VERY VERY painful time now.
This post of mine.. should be VERY easy, if I used RegExp. Should be solved in 3 minutes.
Now I am struggling 3 more days - I am beginner in SQLite.
Here, I have posted SQLite help for RegeExp, actually RegExp part is fine, I have problem with CallBack function's alien return language.
SQLite/AutoHotkey, I have problem with Encoding of sqlite3_result_text return function
I have posted similar help post earlier. And got a nice answer.
I'd like to have Characters only (no signs, numbers and spaces at all)
Remove signs, numbers and spaces
"abc D E F 0123456789 !##$%^&*-+ _<>()[]{}~ =|\?:;''`., /"
But.. unfortunately I have failed to use it (failed to understand it, my bad) And.. got slightly different ideas too - considering different Languages not only ASCII-English but also Chinese/Japanese/Korean too).
So, I wrote quite straightforward method, like this;
UPDATE myTable SET myCOL = lower(
replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(
replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(myCOL
, '0', ''), '1', ''), '2', ''), '3', ''), '4', ''), '5', ''), '6', ''), '7', ''), '8', ''), '9', '')
, '!', ''), '#', ''), '#', ''), '$', ''), '%', ''), '^', ''), '&', ''), '*', ''), '-', ''), '+', ''));
UPDATE myTable SET myCOL = replace(
replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(
replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(myCOL
, '_', ''), '<', ''), '>', ''), '(', ''), ')', ''), '[', ''), ']', ''), '{', ''), '}', ''), '~', '')
, '=', ''), '|', ''), '\', ''), '?', ''), ':', ''), ';', ''), '''', ''), '`', ''), '.', ''), ',', ''), ' ', '');
It has 40 plain functions, one lower case and remove space - in total 42 functions.
Query works fine, I have confirmed.
Looks... beginnish.
Any better ideas?
Thanks..

Replacing key from one dictionary with the key from another

Suppose I have 2 dictionaries:
Dict #1:
statedict = {'Alaska': '02', 'Alabama': '01', 'Arkansas': '05', 'Arizona': '04', 'California':'06', 'Colorado': '08', 'Connecticut': '09','DistrictOfColumbia': '11', 'Delaware': '10', 'Florida': '12', 'Georgia': '13', 'Hawaii': '15', 'Iowa': '19', 'Idaho': '16', 'Illinois': '17', 'Indiana': '18', 'Kansas': '20', 'Kentucky': '21', 'Louisiana': '22', 'Massachusetts': '25', 'Maryland': '24', 'Maine': '23', 'Michigan': '26', 'Minnesota': '27', 'Missouri': '29', 'Mississippi': '28', 'Montana': '30', 'NorthCarolina': '37', 'NorthDakota': '38', 'Nebraska': '31', 'NewHampshire': '33', 'NewJersey': '34', 'NewMexico': '35', 'Nevada': '32', 'NewYork': '36', 'Ohio': '39', 'Oklahoma': '40', 'Oregon': '41', 'Pennsylvania': '42', 'PuertoRico': '72', 'RhodeIsland': '44', 'SouthCarolina': '45', 'SouthDakota': '46', 'Tennessee': '47', 'Texas': '48', 'Utah': '49', 'Virginia': '51', 'Vermont': '50', 'Washington': '53', 'Wisconsin': '55', 'WestVirginia': '54', 'Wyoming': '56'}
Dict #2:
master_dict = {'01': ['01034','01112'], '06': ['06245', '06025, ''06007'], '13': ['13145']}
*The actual master_dict is much longer.
Basically, I want to replace the 2-digit keys in master_dict with the long name keys in statedict. How do I do this? I am trying to use the following, but it doesn't quite work.
for k, v in master_dict.items():
for state, fip in statedict.items():
if k == fip:
master_dict[k] = statedict[state]
You can use a dictionary comprehension to make a lookup table mapping values to keys. A second dictionary comprehension performs the lookups to replace numbers with words:
lookup = {v: k for k, v in statedict.items()}
result = {lookup[k]: v for k, v in master_dict.items()}
print(result)
Output:
{'Alabama': ['01034', '01112'],
'California': ['06245', '06025, 06007'],
'Georgia': ['13145']}
Try it here

Resources