𝙐𝙣𝙧𝙚𝙖𝙡 𝘾𝙤𝙙𝙚𝙧
1.64K subscribers
6 photos
7 files
34 links
A place for coders ;)
Download Telegram
#py #flask
How to check headers property using flask

from flask import request

# check dict
uneeq_header = request.headers.get("uneeq",None)

if not uneeq_header:
print("uneeq property doesn't seems to be verified")
#bestPractice #php #js #py
Join an array into String in (PHP, JS, PY)

Bad practice:
//python
print("a" + " " + "b)

//php
echo "a"." ".b";

Best Practice:
// js
console.log(["a", "b"].join(" "));

//python
print(" ".join(["a", "b"])

//php
echo implode(" ", ["a", "b"]);
#py
Convert a string into dict in Py

def strDict(string):
result = {}
pairs = string.split(";")
for pair in pairs:
if "=" in pair:
split_pair = pair.split("=", 1)
if len(split_pair) == 2:
key, value = split_pair
result[key.strip()] = value.strip()
return result
#py
Divide a string into parts in Py

def divide_string(string, parts=4):
if len(string) % parts == 0:
part_length = len(string) // parts
return [string[i:i+part_length] for i in range(0, len(string), part_length)]
else:
return None
How to merge 2 or many json dict into One in (Python, PHP, JS)

#js
var b = { success:true }
var c = { message: "something", ...b }
console.log(c)


Usage: Use "var" keyword to re assign the variable and use spread method to merge "...json object "

#php
$b = [ "success"=> true ];
$c = ["biswa":"string"];
array_merge($b, $c)

Usage: array_merge used to merge arrays into one array and we need use json_decode and json_encode to make a json obj

#py

Best way to merge in python is using unpacking operator **dict_name here is example:

b = { "success":True }
c = { "hell":None}
print({**b, **c})
😱7😢5🤮4💩4😁3🤬3👎2🤔2👍1🔥1🤯1