Created
August 10, 2020 12:13
-
-
Save khalidelboray/c60e6050374cfe519f028d2a102f0319 to your computer and use it in GitHub Desktop.
hints
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| file_lines = ['a line','another one ','',' ','last','> we want this','> and this'] | |
| print("First Code said \n") | |
| # Get lines that starts with ">" and not empty | |
| for line in (l for l in file_lines if l.strip() and l.startswith(">") ) : | |
| print(line) | |
| # An empty line dosen't start with a ">" so the code can be shortened to | |
| print("Second code said \n") | |
| for line in (l for l in file_lines if l.startswith(">") ) : | |
| print(line) | |
| my_dict = {'a':[1,2,3]} | |
| print(my_dict) | |
| # Now we append a value to the 'b' key in my_dict, using setdefault before append setes the value of 'b' to an empty array if it's not already set | |
| my_dict.setdefault('b',[]).append(3) | |
| print(my_dict) | |
| if 'c' not in my_dict: | |
| my_dict['c'] = [] | |
| my_dict['c'].append(4) | |
| print(my_dict) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| First Code said | |
| > we want this | |
| > and thisSecond code said | |
| > we want this | |
| > and this | |
| {'a': [1, 2, 3]} | |
| {'a': [1, 2, 3], 'b': [3]} | |
| {'a': [1, 2, 3], 'b': [3], 'c': [4]} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment