Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1#!/usr/bin/env python3 

2"""Solution to chapter 5, exercise 19: passwd_to_dict""" 

3 

4 

5def passwd_to_dict(filename): 

6 """Expects to get a string argument, the name of a file in passwd format. 

7Returns a dictionary in which the keys are the usernames from the file, 

8and the values are the user IDs from the file. The user IDs should be 

9returned as integers. 

10""" 

11 users = {} 

12 with open(filename) as f: 

13 for line in f: 

14 if not line.startswith('#') and line.strip(): 

15 user_info = line.split(':') 

16 users[user_info[0]] = int(user_info[2]) 

17 return users