Create an account


Welcome, Guest
You have to register before you can post on our site.

Username
  

Password
  





Search Forums

(Advanced Search)

Forum Statistics
» Members: 20,125
» Latest member: udwivedi923
» Forum threads: 21,822
» Forum posts: 22,691

Full Statistics

Online Users
There are currently 1005 online users.
» 0 Member(s) | 999 Guest(s)
Applebot, Baidu, Bing, DuckDuckGo, Google, Yandex

 
  [Tut] How to Convert an Octal Escape Sequence in Python – And Vice Versa?
Posted by: xSicKxBot - 12-08-2022, 01:23 PM - Forum: Python - No Replies

How to Convert an Octal Escape Sequence in Python – And Vice Versa?

5/5 – (1 vote)

This tutorial will show you how to convert an

  • octal escape sequence to a Python string, and a
  • Python string to an octal escape sequence.

But let’s quickly recap what an octal escape sequence is in the first place! ?

This is you and your friend celebrating after having solved this problem! ?

What Is An Octal Escape Sequence??


An Octal Escape Sequence is a backslash followed by 1-3 octal digits (0-7) such as \150 which encodes the ASCII character 'h'. Each octal escape sequence encodes one character (except invalid octal sequence \000). You can chain together multiple octal escape sequences to obtain a word.

Problem Formulation


? Question: How to convert an octal escape sequence to a string and vice versa in Python?

Examples



Octal String
\101 \102 \103 'ABC'
\101 \040 \102 \040 \103 'A B C'
\141 \142 \143 'abc'
\150 \145 \154 \154 \157 'hello'
\150 \145 \154 \154 \157 \040 \167 \157 \162 \154 \144 'hello world'

Python Octal to String Built-In Conversion


You don’t need to “convert” an octal escape sequence to a Unicode string if you already have it represented by a bytes object. Python automatically resolves the encoding.

See here:

>>> b'\101\102\103'
b'ABC'
>>> b'101\040\102\040\103'
b'101 B C'
>>> b'\101\040\102\040\103'
b'A B C'
>>> b'\141\142\143'
b'abc'
>>> b'\150\145\154\154\157'
b'hello'
>>> b'\150\145\154\154\157\040\167\157\162\154\144'
b'hello world'

Python Octal to String Explicit Conversion


The bytes.decode('unicode-escape') function converts a given bytes object represented by an (octal) escape sequence to a Python string. For example, br'\101'.decode('unicode-escape') yields the Unicode (string) character 'A'.

def octal_to_string(x): ''' Converts an octal escape sequence to a string''' return x.decode('unicode-escape')

Example: Convert the octal representations presented above:

octals = [br'\101\102\103', br'\101\040\102\040\103', br'\141\142\143', br'\150\145\154\154\157', br'\150\145\154\154\157\040\167\157\162\154\144'] for octal in octals: print(octal_to_string(octal)) 

This leads to the following expected output:

ABC
A B C
abc
hello
hello world

Python String to Octal


To convert a Python string to an octal escape sequence representation, iterate over each character c and convert it to an octal escape sequence using oct(ord©).

The result uses octal representation such as '0o123'. You can do string manipulation, such as slicing and string concatenation, to bring it into the final version '\123', for instance.

Here’s the function that converts string to octal escape sequence format:

def string_to_octal(x): ''' Converts a string to an octal escape sequence''' return '\\' + '\\'.join(oct(ord©)[2:] for c in x)

✅ Background:

  • The ord() function takes a character (=string of length one) as an input and returns the Unicode number of this character. For example, ord('a') returns the Unicode number 97. The inverse function of ord() is the chr() function, so chr(ord('a')) returns the original character 'a'.
  • The oct() function takes one integer argument and returns an octal string with prefix "0o".

Let’s check how our strings can be converted to the octal escape sequence representation using this function:

strings = ['ABC', 'A B C', 'abc', 'hello', 'hello world'] for s in strings: print(string_to_octal(s))

And here’s the expected output:

\101\102\103
\101\40\102\40\103
\141\142\143
\150\145\154\154\157
\150\145\154\154\157\40\167\157\162\154\144

If you don’t like the one-liner solution provided above, feel free to use this multi-liner instead that may be easier to read:

def string_to_octal(x): ''' Converts a string to an octal escape sequence''' result = '' for c in x: result += '\\' + oct(ord©)[2:] return result

If you want to train your Python one-liner skills instead, check out my book! ?

Python One-Liners Book: Master the Single Line First!


Python programmers will improve their computer science skills with these useful one-liners.

Python One-Liners

Python One-Liners will teach you how to read and write “one-liners”: concise statements of useful functionality packed into a single line of code. You’ll learn how to systematically unpack and understand any line of Python code, and write eloquent, powerfully compressed Python like an expert.

The book’s five chapters cover (1) tips and tricks, (2) regular expressions, (3) machine learning, (4) core data science topics, and (5) useful algorithms.

Detailed explanations of one-liners introduce key computer science concepts and boost your coding and analytical skills. You’ll learn about advanced Python features such as list comprehension, slicing, lambda functions, regular expressions, map and reduce functions, and slice assignments.

You’ll also learn how to:

  • Leverage data structures to solve real-world problems, like using Boolean indexing to find cities with above-average pollution
  • Use NumPy basics such as array, shape, axis, type, broadcasting, advanced indexing, slicing, sorting, searching, aggregating, and statistics
  • Calculate basic statistics of multidimensional data arrays and the K-Means algorithms for unsupervised learning
  • Create more advanced regular expressions using grouping and named groups, negative lookaheads, escaped characters, whitespaces, character sets (and negative characters sets), and greedy/nongreedy operators
  • Understand a wide range of computer science topics, including anagrams, palindromes, supersets, permutations, factorials, prime numbers, Fibonacci numbers, obfuscation, searching, and algorithmic sorting

By the end of the book, you’ll know how to write Python at its most refined, and create concise, beautiful pieces of “Python art” in merely a single line.

Get your Python One-Liners on Amazon!!



https://www.sickgaming.net/blog/2022/12/...ice-versa/

Print this item

  [Tut] Chart JS Pie Chart Example
Posted by: xSicKxBot - 12-08-2022, 01:23 PM - Forum: PHP Development - No Replies

Chart JS Pie Chart Example

by Vincy. Last modified on December 7th, 2022.

In this tutorial, we are going to learn how to create a pie chart using JavaScript libraries. We have used Chart.js library for the generating the pie charts. As an alternate option, I have also presented a 3d pie chart example using Google charts library.

Let us see the following examples of creating a pie chart using JavaScript.

  • Quick example – Simple pie chart example via ChartJS.
  • 3D pie chart with Google Charts library.
  • Responsive ChartJS pie chart.

Quick example – Simple pie chart example via ChartJS


<!DOCTYPE html>
<html>
<head>
<title>Chart JS Pie Chart</title>
<link rel='stylesheet' href='style.css' type='text/css' />
</head>
<body> <div class="phppot-container"> <h1>Responsive Pie Chart</h1> <div> <canvas id="pie-chart"></canvas> </div> </div> <script src="https://cdn.jsdelivr.net/npm/chart.js@4.0.1/dist/chart.umd.min.js"></script> <script> new Chart(document.getElementById("pie-chart"), { type : 'pie', data : { labels : [ "Lion", "Horse", "Elephant", "Tiger", "Jaguar" ], datasets : [ { backgroundColor : [ "#51EAEA", "#FCDDB0", "#FF9D76", "#FB3569", "#82CD47" ], data : [ 418, 263, 434, 586, 332 ] } ] }, options : { title : { display : true, text : 'Chart JS Pie Chart Example' } } }); </script>
</body>
</html>

Creating a ChartJS pie chart is a three-step process as shown below.

  1. Add the ChartJS library include to the head section of your HTML.
  2. Add a canvas element to the HTML.
  3. Add the ChartJS class initiation and invoking script before closing the HTML body tag.

About the ChartJS pie chart script


The script sets the following properties to initiate the ChartJS library.

  • type – The type of the chart supported by the ChartJS library.
  • data – It sets the chart labels and datasets. The dataset contains the data array and the display properties.
  • options – It sets the chart title text and its display flag as a boolean true to show it on the browser.

Output:

chartjs pie chart

In a previous tutorial, we have seen the various ways of creating line charts using the Chart JS library.

View Demo

Creating 3D pie chart


There is no option for a 3D pie chart using chart JS. For those users who have landed here looking for a 3D pie chart, you may try Google Charts.

This example uses Google Charts to create a 3D pie chart for a webpage. In a previous code, we use Google Charts to render a bar chart to show students’ attendance statistics.

The Google Charts JavaScript code prepares the array of animal distribution data. This array is for sending it to the chart data table which helps to draw the pie chart.

The Google Charts library accepts the is3D with a boolean true to output a 3D pie chart.

It creates a chart visualization object with the reference with respect to the UI element target. Then, it calls the Google Charts library function to draw and render the chart.

<!DOCTYPE html>
<html>
<head>
<title>3d Pie Chart JavaScript with Google Charts</title>
<link rel='stylesheet' href='style.css' type='text/css' /> <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript"> google.charts.load("current", { packages : [ "corechart" ] }); google.charts.setOnLoadCallback(drawChart); function drawChart() { var data = google.visualization.arrayToDataTable([ [ 'Animal', 'Distribution' ], [ 'Horse', 11 ], [ 'Elephant', 2 ], [ 'Tiger', 2 ], [ 'Lion', 2 ], [ 'Jaguar', 7 ] ]); var options = { title : '3d Pie Chart JavaScript with Google Charts', is3D : true, }; var chart = new google.visualization.PieChart(document .getElementById('3d-pie-chart')); chart.draw(data, options); }
</script>
</head>
<body> <div class="phppot-container"> <h1>3d Pie Chart JavaScript with Google Charts</h1> <div id="3d-pie-chart" style="width: 700px; height: 500px;"></div> </div>
</body>
</html>

3d pie chart

Responsive pie chart using Chart JS


The Chart JS library provides JavaScript options to make the output pie chart responsive.

This example script uses those options to render a responsive pie chart in a browser.

The JavaScript code to render a responsive pie chart is the same as we have seen in the quick example above.

The difference is nothing but to set responsive: true in the ChartJS options properties.

If you want to create a responsive chart using Google Charts, then the linked article has an example.

<!DOCTYPE html>
<html>
<head>
<title>Responsive Pie Chart</title>
<link rel='stylesheet' href='style.css' type='text/css' />
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body> <div class="phppot-container"> <h1>Responsive Pie Chart</h1> <div> <canvas id="pie-chart"></canvas> </div> </div> <script src="https://cdn.jsdelivr.net/npm/chart.js@4.0.1/dist/chart.umd.min.js"></script> <script> new Chart(document.getElementById("pie-chart"), { type : 'pie', data : { labels : [ "Lion", "Horse", "Elephant", "Tiger", "Jaguar" ], datasets : [ { backgroundColor : [ "#51EAEA", "#FCDDB0", "#FF9D76", "#FB3569", "#82CD47" ], data : [ 418, 263, 434, 586, 332 ] } ] }, options : { title : { display : true, text : 'Responsive Pie Chart' }, responsive : true } }); </script>
</body>
</html>

View DemoDownload

↑ Back to Top



https://www.sickgaming.net/blog/2022/12/...t-example/

Print this item

  (Indie Deal) Cyber Whale Bundle 2, Cashback, Devil in Me's out
Posted by: xSicKxBot - 12-08-2022, 01:22 PM - Forum: Deals or Specials - No Replies

Cyber Whale Bundle 2, Cashback, Devil in Me's out

Cyber Whale Bundle 2 | 6 Steam Games | 96% OFF
[www.indiegala.com]
Add to your collection & get a selection of games made with heart and mind brought to you by Whale Rock Games for the passionate gamers: Synthwave Burnout, NeuraGun, Inquisitor's Heart and Soul, Cybernetic Fault, Cyberpunk SFX, Euphoria: Supreme Mechanics.

https://www.youtube.com/watch?v=p6_hzXmQt3A
Blackfriday Cashback Sale
[www.indiegala.com]
For a limited time, any purchase made on IndieGala, be it store deals or bundles, will be rewarding you instantly and handsomely, directly into your IndieGala account, ready to be used!
[www.indiegala.com]
https://www.youtube.com/watch?v=wAw5RROD3ZI


https://steamcommunity.com/groups/indieg...7229708288

Print this item

  (Free Game Key) Saints Row IV Re-Elected and Wildcat Gun Machine - Free Epic Games
Posted by: xSicKxBot - 12-08-2022, 01:22 PM - Forum: Deals or Specials - No Replies

Saints Row IV Re-Elected and Wildcat Gun Machine - Free Epic Games

2 Free Epic Games Games

❤️ Saints Row IV Re-Elected
https://store.epicgames.com/p/saints-row-iv-re-elected

❤️ Wildcat Gun Machine
https://store.epicgames.com/p/wildcat-gun-machine-c66c4e

This game is free to keep if claimed by December 15, 2022 5:00 PM or in 7 days

Next weeks freebies:
Mystery Game (15 days of charismas giveaways, a giveaway a day)



We are welcoming everyone to join our discord[discord.gg]. We are more active there on finding giveaways, small or large, and there are daily raffles you can participate.

?GrabFreeGames.com ?Twitter ?Steam Curator ?Facebook[fb.me]?Discord[discord.gg]
❤️Support us: HumbleBundle Partner[www.humblebundle.com] Fanatical Affiliate[www.fanatical.com]


https://steamcommunity.com/groups/GrabFr...3040654188

Print this item

  News - Call Of Duty Has A Long, Strange History On Nintendo Consoles
Posted by: xSicKxBot - 12-08-2022, 01:22 PM - Forum: Lounge - No Replies

Call Of Duty Has A Long, Strange History On Nintendo Consoles

Microsoft's recent announcement that it intends to put Call Of Duty games onto Nintendo consoles for the next 10 years came as a surprise to many. After all, the best-selling shooter franchise has not yet appeared on the Nintendo Switch, despite that console holding onto a huge portion of market share for years now.

However, the truth is that despite Nintendo's reputation as a more "kid-friendly" publisher, several COD games have appeared on its consoles in the past. In fact, it's only in the past decade or so that the Tokyo gaming giant has completely divested itself of the famed series, and we can't help but wonder if that'll change soon.

Early Call Of Duty fans may remember the days of console-exclusive spin-offs like Finest Hour and Big Red One in the mid-2000's, which came out for the GameCube, PS2, and Xbox. In fact, the first COD game was PC-exclusive, which limited its appeal. That would change in subsequent years, of course.

Continue Reading at GameSpot

https://www.gamespot.com/articles/call-o...01-10abi2f

Print this item

  PC - Call of Duty: Warzone 2.0
Posted by: xSicKxBot - 12-08-2022, 01:22 PM - Forum: New Game Releases - No Replies

Call of Duty: Warzone 2.0



As shown at Call of Duty: Next, Call of Duty: Warzone 2.0, the sequel to the seminal Battle Royale experience over 125 million players dropped in to play, is set to arrive this November 16, as part of Modern Warfare II's Season One.

This massive, free-to-play offering leverages new technology shared with Modern Warfare II, introduces a host of new innovations, and continues the new era of Call of Duty coming this Fall, starting with Modern Warfare II's launch on October 28.

Publisher: Activision

Release Date: Nov 16, 2022




https://www.metacritic.com/game/pc/call-...warzone-20

Print this item

  [Oracle Blog] Accelerate Your Java Programming Career
Posted by: xSicKxBot - 12-07-2022, 06:41 AM - Forum: Java Language, JVM, and the JRE - No Replies

Accelerate Your Java Programming Career

Looking for a flexible and affordable way to get started with Java SE? Look no further.


https://blogs.oracle.com/java/post/accel...ing-career

Print this item

  [Tut] Python | Split String Variable Spaces
Posted by: xSicKxBot - 12-07-2022, 06:41 AM - Forum: Python - No Replies

Python | Split String Variable Spaces

Rate this post

⭐Summary: The most efficient way to split a string using variable spaces is to use the split function like so given_string.split(). An alternate approach is to use different functions of the regex package to split the string at multiple whitespaces.

Minimal Example


text = "a b c d"
# Method 1
print(text.split())
# Method 2
import re
print(re.split('\s+', text))
# Method 3
print([x for x in re.findall(r'\S+', text) if x != ''])
# Method 4
print(re.sub(r'\s+', ',', text).split(','))
# Method 5
print(list(filter(None, text.split()))) # ['a', 'b', 'c', 'd']

Problem Formulation


?Problem: Given a string. How will you split the string using multiple spaces?

Example


# Input
text = "abc xyz lmn pqr"
# Output
['abc', 'xyz', 'lmn', 'pqr']

The given input has multiple spaces between each substring, i.e., there are three spaces after abc, two spaces after xyz while a single space after lmn. So, not only do you have multiple spaces between the substring but also varied number of spaces. Can you split the string by varied and multiple spaces?


Though the question might look daunting at first but once you get hold of it, the solutions to this problem are easier than one can imagine. So, without further delay let us dive into the different ways of solving the given problem.

Method 1: Using split()


The built-in split('sep') function allows you to split a string in Python based on a given delimiter. By default the split function splits a given string at whitespaces. Meaning, if you do not pass any delimiter to the split function then the string will be split at whitespaces.

You can use this default property of the split function and successfully split the given string at multiple spaces just by using the split() function.

Code:

text = "abc xyz lmn pqr"
print(text.split()) # ['abc', 'xyz', 'lmn', 'pqr']

?Recommended DigestPython String split()

Method 2: Using re.split


The re.split(pattern, string) method matches all occurrences of the pattern in the string and divides the string along the matches resulting in a list of strings between the matches. For example, re.split('a', 'bbabbbab') results in the list of strings ['bb', 'bbb', 'b'].

Approach: To split the string using multiple space characters use re.split("\s+", text) where \s+ is the matching pattern and it represents a special sequence that returns a match whenever it finds any whitespace character and splits the string. So, whenever there’s a space or multiple spaces (any number of occurrences of space are whitespace characters) the string will be split.

Code:

import re
text = "abc xyz lmn pqr"
print(re.split('\s+', text))
# ['abc', 'xyz', 'lmn', 'pqr']

?Recommended Read:  Python Regex Split.

Method 3: Using re.findall


The re.findall(pattern, string) method scans the string from left to right, searching for all non-overlapping matches of the pattern. It returns a list of strings in the matching order when scanning the string from left to right.

?Recommended Read: Python re.findall() – Everything You Need to Know

Code:

import re
text = "abc xyz lmn pqr"
print([x for x in re.findall(r'\S+', text) if x != ''])
# ['abc', 'xyz', 'lmn', 'pqr']

Method 4: Using re.sub


The regex function re.sub(P, R, S) replaces all occurrences of the pattern P with the replacement R in string S. It returns a new string. For example, if you call re.sub('a', 'b', 'aabb'), the result will be the new string 'bbbb' with all characters 'a' replaced by 'b'.

Approach: Use the re.sub method to replace all occurrences of space characters in the given string with a comma. Thus, the string will now have commas instead of space characters and you can simply split it using a normal string split method by passing comma as the delimiter.

Silly! Isn’t it? Nevertheless, it works.

Code:

import re
text = "abc xyz lmn pqr"
res = re.sub(r'\s+', ',', text).split(',')
print(res)
# ['abc', 'xyz', 'lmn', 'pqr']

Method 5: Using filter


Python’s built-in filter() function filters out the elements that pass a filtering condition. It takes two arguments: function and iterable. The function assigns a Boolean value to each element in the iterable to check whether the element will pass the filter or not. It returns an iterator with the elements that pass the filtering condition.

?Related Read: Python filter()

Approach: You can use the filter() method to split the string by space. Feed in None as the first argument and the list of split strings as the second argument into the filter function. The filter() function then iterates through the list and filters out the spaces from the given string and returns only the non-whitespace characters. As the filter() method returns an object, we need to use the list() to convert the object into a list.

Code:

text = "abc xyz lmn pqr"
print(list(filter(None, text.split())))
# ['abc', 'xyz', 'lmn', 'pqr']

Conclusion


Hurrah! We have successfully solved the given problem using as many as five different ways. I hope you enjoyed reading this article and it helped you in your Python coding journey. Please subscribe and stay tuned for more interesting articles!

Happy coding! ?

?Suggested Read: Python Regex Superpower [Full Tutorial]


Do you want to master the regex superpower? Check out my new book The Smartest Way to Learn Regular Expressions in Python with the innovative 3-step approach for active learning: (1) study a book chapter, (2) solve a code puzzle, and (3) watch an educational chapter video.



https://www.sickgaming.net/blog/2022/12/...le-spaces/

Print this item

  (Indie Deal) Development Update #3 - Elcado Needs Help
Posted by: xSicKxBot - 12-07-2022, 06:41 AM - Forum: Deals or Specials - No Replies

Development Update #3 - Elcado Needs Help


Greetings Mercenaries,

For this Friday’s devlog, we wanted to show you our most recent YouTube video highlighting some of the exciting things the development team has been working on.

While you’re checking the video out, be sure to head over to IndieGala[freebies.indiegala.com] or Steam to play the new Vorax alpha 0.3, which is still available for a limited time

“Bilial-Like” Creatures Stalk the Night
There are more dangerous things than simple zombies that lurk in the dark on the island. Not only do they present a physical threat, but their terrifying appearance will test even the most hardened mercenary’s sanity.

While it can be dangerous to engage them, they often drop special loot that can be extremely useful. Remember, good things come to those that are brave.

Sergeant Elcado Needs Help

While much of the island has been ravaged by the virus, there are still people who have managed to survive. One such survivor is Sergeant Elcado, who is the only surviving member of a NATO squad sent to investigate the ongoing events on the island. Survivors like him can often help you throughout your mission, but they will often ask that you do something for them in exchange.

Community Highlight: Gameplay Versatility & Compatibility
One of our goals in developing Vorax, is to provide the player with multiple different ways to play the game. Whether it’s going in guns blazing, or cleverly trapping an area to avoid fighting enemies head on, we want the player to choose how they approach each and every situation.
https://youtu.be/6FZJgo-0c2s
To highlight this, check out some of the content created by our community members showcasing how they tackle difficult situations.

What's next?
That’s all for this week, everyone. But look forward to the next one when we will take a closer look at some of the strategic aspects of the game, such as trap crafting and building fortifications.

Remember, the Open Alpha is still available for those of you wishing to experience some of the new content and updates we’ve added to the game. Also, be sure to join our Discord to get exclusive news on updates, events, and more.

Wishlist now:
https://store.steampowered.com/app/1874190/Vorax/
[discord.gg]


https://steamcommunity.com/groups/indieg...3395007889

Print this item

  (Free Game Key) Fort Triumph and RPG in a box - Free Epic Games
Posted by: xSicKxBot - 12-07-2022, 06:41 AM - Forum: Deals or Specials - No Replies

Fort Triumph and RPG in a box - Free Epic Games

❤️ Fort Triumph
https://store.epicgames.com/p/fort-triumph


❤️ RPG in a Box
https://store.epicgames.com/p/rpg-in-a-box

This game is free to keep if claimed by December 8, 2022 5:00 PM

Next weeks freebies:
Saints Row IV Re-Elected
Wildcat Gun Machine


We are welcoming everyone to join our discord[discord.gg]. We are more active there on finding giveaways, small or large, and there are daily raffles you can participate.

?GrabFreeGames.com ?Twitter ?Steam Curator ?Facebook[fb.me]?Discord[discord.gg]
❤️Support us: HumbleBundle Partner[www.humblebundle.com] Fanatical Affiliate[www.fanatical.com]


https://steamcommunity.com/groups/GrabFr...2920688459

Print this item

 
Latest Threads
Shein Coupon & Promo Cod...
Last Post: udwivedi923
4 hours ago
"Updated" Shein Coupon & ...
Last Post: udwivedi923
4 hours ago
"Updated" Shein Coupon & ...
Last Post: udwivedi923
4 hours ago
[40% OFF 【Shein Coupon &...
Last Post: udwivedi923
4 hours ago
[$200 OFF 【Shein Coupon ...
Last Post: udwivedi923
4 hours ago
[$300 OFF 【Shein Coupon ...
Last Post: udwivedi923
4 hours ago
[$50 OFF 【Shein Coupon &...
Last Post: udwivedi923
4 hours ago
"Updated" Shein Coupon & ...
Last Post: udwivedi923
4 hours ago
{SPECIAL} Shein Coupon Co...
Last Post: udwivedi923
5 hours ago
{SPECIAL} Shein Coupon Co...
Last Post: udwivedi923
5 hours ago

Forum software by © MyBB Theme © iAndrew 2016