avatar Bite 257. Extract users dict from a multiline string

A quick Bite to practice some string parsing extracting a users dict from a password file.

Complete get_users is how it works:

>>> from users import get_users
>>> pw = """
... postfix:x:108:112::/var/spool/postfix:/bin/false
... ssh-rsa:x:1004:1004::/home/ssh-rsa:/bin/bash
... artagnon:x:1005:1005:Ramkumar R,,,,Git GSOC:/home/artagnon:/bin/bash
... """
>>> get_users(pw)
{'postfix': 'unknown', 'ssh-rsa': 'unknown', 'artagnon': 'Ramkumar R Git GSOC'}

So keys are usernames, values are names. Note that commas inside the name get replace by a single space. Trailing commas (not in this example) get stripped off.

Have fun and keep calm and code in Python!

Login and get coding
go back Beginner level
Bitecoin 2X

101 out of 101 users completed this Bite.
Will you be Pythonista #102 to crack this Bite?
Resolution time: ~39 min. (avg. submissions of 5-240 min.)
Pythonistas rate this Bite 3.2 on a 1-10 difficulty scale.
» You can do it! 😌

We use Python 3.8