Python - Read a text file into a dictionary

Python - Read a text file into a dictionary

george boole

11 лет назад

81,189 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

@jadenataylor
@jadenataylor - 13.03.2023 20:01

Thank you!

Ответить
@CROPSHOP97
@CROPSHOP97 - 13.05.2022 10:20

George, thank you so much. Was looking for such solution for a long time.

Ответить
@jeanrodrigues6249
@jeanrodrigues6249 - 23.11.2021 19:22

Floppy

Ответить
@amazingcoder6984
@amazingcoder6984 - 18.04.2021 00:33

Thanks Bro

Ответить
@Slimaz01234
@Slimaz01234 - 21.03.2021 22:03

Works like a charm! Thank you!

Ответить
@stoneybaloney5514
@stoneybaloney5514 - 20.11.2020 01:37

the Bob Ross of coding

Ответить
@GG_Booboo
@GG_Booboo - 20.08.2020 05:01

Love how you say "I did something very naughty!" LOL! Love the way you explain, very relevant 7 years later!!!

Ответить
@AmazingJayB51
@AmazingJayB51 - 13.08.2020 07:23

I love you George! I struggle with some of these concept but you explain in a way that I can understand. Thank you!

Ответить
@Radcraft8
@Radcraft8 - 21.04.2020 21:06

You're the best

Ответить
@Radcraft8
@Radcraft8 - 21.04.2020 21:06

Thank you 😊

Ответить
@Marta-xi6vf
@Marta-xi6vf - 05.01.2020 15:09

Thank You! This video helps me a lot. And Your voice is soo soothing. It was pleasure to learn XD

Ответить
@khan5265
@khan5265 - 17.11.2019 14:19

Great got some idea but could you please guide how to make dictionary of sql table ?

Ответить
@YoseffTutorcientificoAmaru
@YoseffTutorcientificoAmaru - 17.08.2019 19:58

nice material for my weekend studies

Ответить
@janamejayvinayjoshi8817
@janamejayvinayjoshi8817 - 05.06.2019 07:46

Thank you! :) You explain it so well!

Ответить
@bealover4u
@bealover4u - 05.04.2019 22:37

George, This is late though. What if the order of the values are changed in the text file and how do you map it to the correct keys. Assuming we know the keys already.

Ответить
@AK-ij4qf
@AK-ij4qf - 24.03.2019 03:59

Omygod THANK YOU, you saved me from a bad grade <3. I hope your channel grows a lot

Ответить
@KingTheZack
@KingTheZack - 28.08.2018 00:38

stop doing heroine dude, please...

Ответить
@juliancaste3914
@juliancaste3914 - 08.07.2018 19:29

"THAT WAS EXCITING" LOL JAJJAJAJAJAJAJA

Ответить
@user-el3el2xq2b
@user-el3el2xq2b - 09.12.2017 03:26

Love you man, saved my day.

Ответить
@wizzypizzy4813
@wizzypizzy4813 - 21.08.2017 05:25

Thanks very much! :)

Ответить
@sweetiestgirl
@sweetiestgirl - 06.04.2017 12:08

This is great, im watching this 4 years later and it helped me a lot, your voice is very soothing as well :)

Ответить
@samayarora7919
@samayarora7919 - 23.03.2017 20:22

hy my teacher gave me assignment can anybody help me???????

Ответить
@georgepeverill6116
@georgepeverill6116 - 16.12.2016 14:34

Adding x[-1] = x[-1].strip() after x = line.split(',')

will also do the trick. It selects the last element in the list x and then strips off whitespace. WhiteSpace is defined as any character or series of characters that represent horizontal or vertical space in typography. When rendered, a whitespace character does not correspond to a visible mark, but typically does occupy an area on a page. Thus running strip without any parameters removes whitespace. Just another way to do the same thing.

Ответить
@UnicornarusRex
@UnicornarusRex - 30.09.2016 20:46

you saved my day last night :D :D :D :D ooh thank you soo much

Ответить
@UnicornarusRex
@UnicornarusRex - 29.09.2016 16:22

thank you so much for this George!

Ответить
@adrianmxmx
@adrianmxmx - 19.08.2016 13:58

Subsrcribed - First time I am actually understanding the problem sets without just the syntax interation, statements and logic practice. Hope to see network programming based off of vendors. Great Work with the naughty explainations made funny.

Ответить
@philipwest4553
@philipwest4553 - 26.04.2016 21:30

there's a much easier solution. Try using d[a]=b[:-1]

Ответить
@johnmcane710
@johnmcane710 - 26.04.2016 19:25

I keep getting the file unsupported not readable

Ответить
@onyekanwamba7094
@onyekanwamba7094 - 31.03.2016 00:33

how do I fix "index list out of range?"

Ответить
@alex-tg9jo
@alex-tg9jo - 25.03.2016 22:42

Thanks, you helped me with my school project

Ответить
@EpicNinjas
@EpicNinjas - 11.03.2016 23:30

I did this however when i go to print(d) it seems that it's only saved the last line of the text file to the dictionary. Any ideas on how to fix this?

Ответить
@lamarts100
@lamarts100 - 09.03.2016 09:50

Great example....what if you have 10 columns as a list of values mapped to the dictionary key? How would you get rid of the "\n"?

Ответить
@dgbene1
@dgbene1 - 05.10.2015 05:45

George, thank you so much. Your videos are very simple, clear and to the point. They're becoming my favorite for python help on.

Ответить
@gustavoramos7236
@gustavoramos7236 - 26.08.2015 00:18

Or, x = line.replace("\n",",").split(","). It works too!

Ответить
@chancewatkins5071
@chancewatkins5071 - 30.06.2015 03:21

Very helpful. You have earned yourself a subscriber. Thanks so much for sharing; Jesus Christ Bless! :)

Ответить
@sageuldor
@sageuldor - 02.01.2015 20:19

Can't we just add "b=x[1:-1]" at the 'b' part?

Ответить
@rahman4242
@rahman4242 - 04.12.2014 13:10

George you can help me ,

Ответить
@chienponion
@chienponion - 11.06.2014 05:06

Thanks for the video.....

Ответить
@davidelm5401
@davidelm5401 - 21.01.2014 05:07

Actually in this case the \n is on the 'b' part so just do:
    b = b[:-1]

Ответить
@davidelm5401
@davidelm5401 - 21.01.2014 05:03

Another way to remove the \n from each line is this:
      x=x[:-1]

Ответить