Skip to content

Instantly share code, notes, and snippets.

@phreax
Last active May 27, 2019 09:52
Show Gist options
  • Save phreax/ed072e8a06acc673f63b00e3bde9f099 to your computer and use it in GitHub Desktop.
Save phreax/ed072e8a06acc673f63b00e3bde9f099 to your computer and use it in GitHub Desktop.
Python Coding Mistakes
# Case 1
def append_index(idx=0, ids=[]):
ids.append(idx)
print(idx)
print(ids)
append_index(idx=1)
append_index(idx=2)
# Case 2
d = {}
datas = [1, 2, 3, 4, 2, 3, 4, 1, 5]
for k in datas:
if k not in d:
d[k] = 0
d[k] += 1
# Case 3
# d is a dict
for k in d:
v = d[k]
print(k, v)
# l is a list
for i in len(l):
v = l[i]
print(i, v)
# Case 4
for i in range(len(numbers)):
if odd(numbers[i]):
del numbers[i]
# Case 5
search_list = ['Jone', 'Aric', 'Luise', 'Frank', 'Wey']
found = False
for s in search_list:
if s.startswith('C'):
found = True
# do something when found
print('Found')
break
if not found:
# do something when not found
print('Not found')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment