T
T
terpizavr2021-04-06 20:28:57
JavaScript
terpizavr, 2021-04-06 20:28:57

How to split string for dictionary?

There is a line 455123-12412412-12414, how to "stick" it into the dictionary, so that the first 6 values ​​​​are the key. The rest, respectively, the value ?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander, 2018-05-21
@alexr64

bool is_clicked = false;

onclick() {
     if(!is_clicked)
     {
          animate()
     } else
     {
          search()
     }
}

S
Sergey Karbivnichy, 2021-04-06
@terpizavr

s = '455123-12412412-12414'

my_key, my_value = s.split('-',1)
my_dict = {my_key:my_value}
print(my_dict) #{'455123': '12412412-12414'}

Or use slices:
s = '455123-12412412-12414'

my_dict = {s[:6]:s[7:]}
print(my_dict)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question