The Most Pythonic Way to Convert a List of Tuples to a String
The most Pythonic way to convert a list of tuples to a string is to use the built-in method str(...). If you want to customize the delimiter string, the most Pythonic way is to concatenate the join() method and the map() function '\n'.join(map(str, lst)) to convert all tuples to strings and gluing those together with the new-line delimiter '\n'.
Exercise: Run the interactive code snippet. Which method do you like most?
Method 1: Default String Conversion
Say, you’ve got a list of tuples, and you want to convert it to a string (e.g., see this SO post). The easiest way to accomplish this is to use the default string conversion method str(...).
The map() function transforms each tuple into a string value, and the join() method transforms the collection of strings to a single string—using the given delimiter '--'. If you forget to transform each tuple into a string with the map() function, you’ll get a TypeError because the join() method expects a collection of strings.
Method 3: Flatten List of Tuples
If you want to flatten the list and integrate all tuple elements into a single large collection of elements, you can use a simple list comprehension statement [str(x) for t in lst for x in t].
lst = [(1,1), (2,1), (4,2)] print('\n'.join([str(x) for t in lst for x in t])) '''
1
1
2
1
4
2 '''
If you want to redefine how to print each tuple—for example, separating all tuple values by a single whitespace character—use the following method based on a combination of the join() method and the map() function with a custom lambda function lambda x: str(x[0]) + ' ' + str(x[1]) to be applied to each list element.
To become successful in coding, you need to get out there and solve real problems for real people. That’s how you can become a six-figure earner easily. And that’s how you polish the skills you really need in practice. After all, what’s the use of learning theory that nobody ever needs?
Practice projects is how you sharpen your saw in coding!
Do you want to become a code master by focusing on practical code projects that actually earn you money and solve problems for people?
Then become a Python freelance developer! It’s the best way of approaching the task of improving your Python skills—even if you are a complete beginner.
Decoupling microservices with Apache Camel and Debezium
The rise of microservices-oriented architecture brought us new development paradigms and mantras about independent development and decoupling. In such a scenario, we have to deal with a situation where we aim for independence, but we still need to react to state changes in different enterprise domains.
I’ll use a simple and typical example in order to show what we’re talking about. Imagine the development of two independent microservices: Order and User. We designed them to expose a REST interface and to each use a separate database, as shown in Figure 1:
Figure 1: Order and User microservices.
We must notify the User domain about any change happening in the Order domain. To do this in the example, we need to update the order_list. For this reason, we’ve modeled the User REST service with addOrder and deleteOrder operations.
Solution 1: Queue decoupling
The first solution to consider is adding a queue between the services. Order will publish events that User will eventually process, as shown in Figure 2:
Figure 2: Decoupling with a queue.
This is a fair design. However, if you don’t use the right middleware you will mix a lot of infrastructure code into your domain logic. Now that you have queues, you must develop producer and consumer logic. You also have to take care of transactions. The problem is to make sure that every event ends up correctly in both the Order database and in the queue.
Solution 2: Change data capture decoupling
Let me introduce an alternative solution that handles all of that work without your touching any line of your microservices code. I’ll use Debezium and Apache Camel to capture data changes on Order and trigger certain actions on User. Debezium is a log-based data change capture middleware. Camel is an integration framework that simplifies the integration between a source (Order) and a destination (User), as shown in Figure 3:
Figure 3: Decoupling with Debezium and Camel.
Debezium is in charge of capturing any data change happening in the Order domain and publishing it to a topic. Then a Camel consumer can pick that event and make a REST call to the User API to perform the necessary action expected by its domain (in our simple case, update the list).
Decoupling with Debezium and Camel
I’ve prepared a simple demo with all of the components we need to run the example above. You can find this demo in this GitHub repo. The only part we need to develop is represented by the following source code:
Apache Camel has a Debezium component that can hook up a MySQL database and use Debezium embedded engine. The source endpoint configuration provides the parameters needed by Debezium to note any change happening in the debezium._order table. Debezium streams the events according to a JSON-defined format, so you know what kind of information to expect. For each event, you will get the information as it was before and after the event occurs, plus a few useful pieces of meta-information.
Thanks to Camel’s content-based router, we can either call the addOrderUsingPOST or deleteOrderUsingDELETE operation. You only have to develop a message translator that can convert the message coming from Debezium:
public class AfterStructToOrderTranslator implements Processor { private static final String EXPECTED_BODY_FORMAT = "{\"userId\":%d,\"orderId\":%d}"; public void process(Exchange exchange) throws Exception { final Map value = exchange.getMessage().getBody(Map.class); // Convert and set body int userId = (int) value.get("user_id"); int orderId = (int) value.get("order_id"); exchange.getIn().setHeader("userId", userId); exchange.getIn().setHeader("orderId", orderId); exchange.getIn().setBody(String.format(EXPECTED_BODY_FORMAT, userId, orderId)); } }
Notice that we did not touch any of the base code for Order or User. Now, turn off the Debezium process to simulate downtime. You will see that it can recover all events as soon as it turns back on!
The example illustrated here uses Debezium’s embedded mode. For more consistent solutions, consider using the Kafka connect mode instead, or tuning the embedded engine accordingly.
The 187th GalaQuiz will be LIVE soon, win up to $50 in GalaCredit!
[www.indiegala.com] The GalaQuiz will take place in less than 15 minutes from this announcement Today's GalaQuiz[www.indiegala.com] hints are up. The theme will be William Shakespeare
Welcome to Week 46 of Box Art Brawl, the poll to find out your favourite box art from a selection of three regional variants.
Last week we looked at SNES shmup Phalanx. Surprisingly, the infamous North American cover picked up over 50% of the vote for an easy victory. Japan came in second and Europe trailed in a distant third place. We totally understand your pick; we’re quite partial to a some banjo ourselves.
This week, partly in honour of SEGA’s 60th anniversary, Sonic returns to the ring with Sonic the Hedgehog 3 for the Mega Drive / Genesis. The game hasn’t turned up on Nintendo consoles as frequently as the previous Mega Drive entries, but it can be found on the GameCube Sonic Mega Collection, the Wii Virtual Console, and also the (quite terrible) Sonic Classic Collection for Nintendo DS.
So, time to get in the zone – the Angel Island Zone, that is!…
Japan
Very much staying with the theme of the Japanese cover of the original game (and the sequel), Sonic 3 gets primary colours, solid blacks and abstract, pointy shapes over a white background, and it also retains its THE MOST FAMOUS HEDGEHOG IN THE WORLD tag from the original – the difference this time, however, is that the tag was true by 1994.
We enjoy how the lineage of the Japanese covers carries across the games, although minus points for ousting ol’ orange in favour of blue and pink alone. Sonic and Knuckles would get their own Tails-less outing in the next game–we forget the name–so it’s a shame Miles Prower isn’t on this cover.
North America
We still have a beautiful supplement that came with SEGA Magazine with this image emblazoned on the front. We love the colour and we love how Robotnik is breaking the red border. We love that Tails is present and we love the creepy eyes of Knuckles hiding in the bushes.
A very strong entry, even if the Genesis logo is a bit rubbish.
Europe
A ‘blue box’ from the later period of Mega Drive releases, Europe delivers a dynamic image with a ‘pointier’ Sonic; a Sonic that apparently can’t count. Yes, we’re being petty, but he’s not even attempting to tuck his left thumb in.
Still, this is another strong entry, with a grouchy Knuckles shaking his fist in the bottom left corner, Carnival Night Zone providing a colourful backdrop, and a kickass ’90s logo running down the left side. There’s a big ‘SEGA’ at the bottom, too – bigger than the others, at least.
We likey, except for the distinct lack of Tails.
Bonus
And as a cheeky bonus, here’s the cover that Asia got outside Japan (and Korea, which enjoyed a borderless version using the same image). It uses the same art as North America, but with a black grid that European gamers will recognise from earlier Mega Drive releases. It’s a little boxy, but very pleasant.
Just three Sonic 3s to choose from, then. We think it’s going to be a close one this week. Click your favourite and hit that ‘Vote’ button to let us know which you prefer:
An article about Sonic and we didn’t say ‘blue blur’ once – get in! Have a fine week, lovely people. Stay safe and we’ll see you again in seven days.
Fortnite Spy Base Locations: Where To Find And Open Faction Chests
Fortnite's Storm the Agency challenges have arrived alongside the game's 12.61 update, giving you a few more tasks to complete before the upcoming Doomsday event ushers in Season 3 of the popular battle royale shooter. One of the trickier challenges from the set asks you to open a faction locked chest at three different spy bases. If you're having trouble hunting those down, this guide will explain where the spy bases are located and how to complete the challenge.
Where Are The Spy Base Locations?
Much like the safe houses you need to visit for a separate Storm the Agency challenge, spy bases have been a fixture of the map since the start of Season 2. These are a bit more overt than the safe houses, however; while those are disguised to look like regular buildings, the spy bases are all named locations, so they're much easier to track down. We've marked down where a few of the chests at these bases are located below:
A Popular VGC Pokémon Could Be Returning In Sword And Shield’s Expansion
It looks like a certain Grass/Poison-type Pokémon that started out in Generation V could be returning in part one of the upcoming Pokémon Sword and Shield expansion.
Twitter user and Pokémon fan @mattyoukhana_ appears to have discovered evidence of the mushroom-like pocket monster Amoonguss in the latest trailer for the game, which was aired earlier this week. This is the evolution of Foongus.
You can see it around the 2:53 mark in a brief shot featuring the expansion logos:
See the smaller image at the top left side of the screen? Here’s a close-up… And this is the Pokémon
As this particular clip appears on the Isle of Armor side of the screen, there’s a theory this Pokémon will show up in part one of the Expansion Pass later this month.
The possible return of this ‘mon is considered to be a big deal by the competitive scene, as it’s become a staple of the Pokémon Video Game Championships over the years. Some replies to the original tweet jokingly suggested it was “the return of the king” whereas other responses weren’t so happy about the discovery.
How would you feel about the return of Amoonguss? Tell us down below.
Borderlands 3 Update Delayed Due To Anti-Racism Protests
Borderlands developer Gearbox Software has joined the chorus in supporting Black Lives Matter and pushing back some of its scheduled plans for Borderlands 3 in solidarity with the movement. In a statement on Twitter, the developer said it's delaying the release of the Takedown at the Guardian Breach update.
Additionally, the studio is muting its Twitter channel--with the exception of this announcement--out of respect for "what's going on in the world right now."
2K Games, which publishes the Borderlands series, said it's adding another $1 million USD to the 2K Foundations Program and expanding its scope to include fighting racial injustice and inequalities in black communities around the world.
Posted by: xSicKxBot - 06-08-2020, 08:53 AM - Forum: Python
- No Replies
{AND, OR, NOT} How to Apply Logical Operators to All List Elements in Python?
Problem: Given a list of Boolean elements. What’s the best way to join all elements using the logical “OR” and logical “AND” operations?
Example: Convert the list [True, True, False] using
The logical “AND” operation to True and True and False = False,
The logical “OR” operation to True or True or False = True, and
The logical “NOT” operation to [not True, not True, not False] = [False, False, True].
Solution:
To perform logical “AND”, use the built-in Python function all(),
To perform logical “OR”, use the built-in Python function any(), and
To perform logical “NOT”, use a list comprehension statement [not x for x in list].
Here’s the solution for our three examples:
lst = [True, True, False] # Logical "AND"
print(all(lst))
# False # Logical "OR"
print(any(lst))
# True # Logical "NOT"
print([not x for x in lst])
# [False, False, True]
This way, you can combine an arbitrary iterable of Booleans into a single Boolean value.
Puzzle: Guess the output of this interactive code snippet—and run it to check if you were correct!
The challenge in the puzzle is to know that Python comes with implicit Boolean type conversion: every object has an associated Boolean value. Per convention, all objects are True except “empty” or “zero” objects such as [], '', 0, and 0.0. Thus, the result of the function call all([True, True, 0]) is False.
Where to Go From Here?
Enough theory, let’s get some practice!
To become successful in coding, you need to get out there and solve real problems for real people. That’s how you can become a six-figure earner easily. And that’s how you polish the skills you really need in practice. After all, what’s the use of learning theory that nobody ever needs?
Practice projects is how you sharpen your saw in coding!
Do you want to become a code master by focusing on practical code projects that actually earn you money and solve problems for people?
Then become a Python freelance developer! It’s the best way of approaching the task of improving your Python skills—even if you are a complete beginner.
Posted by: xSicKxBot - 06-08-2020, 08:53 AM - Forum: Lounge
- No Replies
This Week At Bungie – 5/21/2020
This week at Bungie, something unexpected happened on the way to the Moon Bunker.
Many of you have been chasing a Lie. Last week, you began your hunt with Ana, successfully defending Seraph Towers in the Winding Cove, Anchor of Light, and the Rupture (or watched as your fellow Guardians carried the weight…). You burned through a thousand enemies with your trusty Shotgun. Sadly, your quest for answers came to a halt on Sunday evening, all thanks to a faulty door on the Moon’s bunker.
Earlier this morning, Destiny 2 Hotfix 2.8.1.3 was released, unblocking your journey in finding truth behind The Lie. While we hate to see a bug ship, we’re excited to right the ship as quickly as possible.
Now, we look to what comes next. Season of the Worthy is winding down, which means it’s time for a round of previews from the team. This week, we’re hyper focused on Legendary Engrams and weapon tuning.
Decrypting the Future
Last week, we did a deep dive on how loot will be evolving Season over Season. With the upcoming addition of a Max Power Level to your gear, players have been asking how acquisition methods will be changing. We have a breakdown from the Destiny Dev Team on how we’re keeping the items you earn from Legendary Engrams and core activities relevant during a given Season.
Today we’re going to talk about some changes that are coming in Season 11 to the way the world loot pool works. Because the world pool serves as a baseline of legendary gear that can be earned across different activities, we want to update and refresh it seasonally with meta relevant weapons, some of which were previously exclusive to specific activities like Gambit or Crucible.
This shared pool can also be unwieldy — if you’re looking for a specific roll of a specific weapon, a pool too large can make it statistically challenging to find, much less with the roll you want. Starting in Season 11, it will be curated both for relevance and overall size, to strike a balance between number of rewards and the chance to get a sought-after drop. Every season gear from previous seasons will be added, and any gear that would no longer have a Max Power Level greater than or equal to the current Season cap will be cycled out to ensure that drops are Power relevant in the current Season.
The World Pool for Season 11 will consist of the following weapons:
Uriel’s Gift
Elatha FR4
The Old Fashioned
Mos Epoch III
Hawthorne’s Field-Forged Shotgun
Last Hope
Timelines’ Vertex
Interference VI
Dire Promise
True Prophecy
Jian 7 Rifle
Enigma’s Draw
Distant Tumulus
Escape Velocity
Honor’s Edge
Gnawing Hunger
Arsenic Bite-4b
Main Ingredient
Outrageous Fortune
Truthteller
Nature of the Beast
Last Perdition
Bad Omens
Night Watch
Toil and Trouble
Wishbringer
Last Dance
Lonesome
Long Shadow
Steel Sybil Z-14
If you still need a weapon or weapon roll from the current Vanguard, Crucible, or Gambit playlists that isn’t on that list, go grab it now!
Lock and Reload
Alongside the changes to the World Loot Pool, we have some changes coming to Destiny 2’s Sandbox. This week, we’ll be focused on weapons – specifically perk tuning. Here’s a quick breakdown from the team on what to expect:
Reload Perk Updates
We’ve observed that players lean towards picking perks that increase their damage (e.g. Kill Clip) or reduce weapon downtime (e.g. Outlaw).
The damage perks were adjusted quite a while back, but reload perks still don’t feel like choices. This tuning pass aims to keep them feeling powerful without being so dominant that no other choices seem viable.
First, some information on the stats that impact reload:
Reload Stat: 0-100, and maps onto an archetype-specific reload animation speed.
Reload Duration Scale: Most reload perks also apply a small multiplier to the reload animation, so that if reload stat is capped, you still see a small speed bump.
Reload Empty Duration Scale: As above, but only applies if the magazine is empty.
Note that because most weapons have fairly high reload stats, decreasing a reload stat bonus from +100 to +50 will still max out the reload stat most of the time, and so doesn’t slow down the actual reload as much as it seems.
The following perks that alter these reload stats are being updated:
Outlaw – Slowed this down a little bit.
Reload stat from +100 to +50.
Reload Duration Scale from 0.8 to 0.9.
Feeding Frenzy – This was strictly better than Outlaw, so we’re changing functionality to be based on number of rapid kills.
Functionality changed to increase reload speed based on number of rapid kills, up to 5.
With 2 kills, reload speed is equal to updated Outlaw.
With 3+ kills, is faster than Outlaw.
With 4+ kills, is the fastest reload in the game (except Alloy Mag).
Max possible reload duration scale from 0.83 to 0.8.
Max possible reload stat unchanged at +100.
Rapid Hit – Gave a huge amount of reload and stability for very little work, front-loaded onto the first precision hit. We have updated it so that it still feels good, but isn’t quite as powerful.
Adjusted stacking bonus to give less benefit for the first hit and more with subsequent hits.
Max possible reload stat from +100 to +60.
Max possible reload duration scale from 0.8 to 0.925.
Max possible stability stat from +50 to +25.
Drop Mag – Situationally really powerful without a massive drawback, as good as a perk, but in a magazine column.
Reload duration scale from 0.85 to 0.9 (just brings it in line with Outlaw).
Field Prep – Unchanged, but for reference:
Reload stat +50.
Reload duration scale 0.8.
Alloy Mag – Unchanged, but for reference:
Reload empty duration scale 0.6666.
Additionally, we’re fixing an issue where perks that grant partial weapon ammo did not respect shot count for burst weapons. This means that these perks will now work correctly on Pulse Rifles, Fusion Rifles, and Burst Sidearms, so these perks will be more common on those weapon archetypes in the future:
Slideways
Slideshot
Ambitious Assassin
Subsistence
Overflow
Lead from Gold
Clown Cartridge
General Perk Retuning
With opening up space by adjusting reload perks, we also retuned some other, underused perks, based on our internal testing and perk popularity and effectiveness data from our internal analytics.
Dynamic Sway Reduction — Adds 10 Stability over time in addition to accuracy (this is way more powerful than it sounds).
Reduced reticle movement from Stability should now tell players this is working.
Pulse Monitor — Take critical damage and you can quickly switch to your now-fully loaded Shotgun!
Reload amount from 0.35 to 1.0.
+50 Handling.
5% faster swap speed.
This works on stowed weapons too, which was already the case but makes it a lot more useful.
Hipfire Grip — Now helps you hit shots closer to ADS ranges, still doesn’t affect damage dropoff or magnetism.
1.2x aim assist falloff.
+15 aim assist.
+1.7 degrees precision hip fire angle threshold.
By default, when hip-firing a weapon, the center of your reticle must be over a target in order to get a crit, otherwise aim assist will give you a body shot. This change gives you a little leniency, so if the center of your reticle is not directly over a target you will still get the crit if you’re within this angle.
Has no effect on Sniper Rifles.
Sneak Bow — Actually makes you sneaky now. Stealth buff!
Now doesn’t ping radar when shooting.
New Perks
Next Season, we’ll have new perks rolling exclusively on the Season of [REDACTED] weapons. Additionally, Iron Banner will be receiving two new perks on two reprised weapons. In future Seasons, these perks will begin to roll on other weapons.
While we don’t want to spoil the fun of discovering and testing new perks, we will leave you with the names of upcoming Iron Banner perks: Iron Grip and Iron Gaze. We are excited to see the community break these perks down when the new Season begins.
Upcoming Archetype Buffs
Next Season, we’re taking a quick pass on a few weapon archetypes that have been underperforming.
Slug Shotguns are underused in PvE, because they require crits to maximize damage, and didn’t reward that precision with higher damage per second.
Slug Shotgun PvE Damage + 30%.
High-Impact Pulse Rifles are underused in Crucible. While they have a very fast optimal TTK, that TTK was very hard to achieve, so we decided to soften that a little.
High-Impact Pulse Rifle damage per bullet from 21 to 22. This changes it from 6 crits to 5 crits/1 body to kill a Guardian in PvP at most Resilience values.
In analytics we see Bows are underused in challenging content, and locally we’ve observed that it feels terrible when a Bow leaves a red bar enemy at low health.
Bow PvE damage VS minors + 10%.
Future Archetype Updates
We’ve been evaluating feedback and our analytics data, and while we’re not done yet, we wanted to touch on three community pain points. Our current goal is to touch on these in Season 12, but we’ll be sure to let you know if plans change.
Sniper Rifles – Community feedback has been that Revoker and Beloved dominate, and looking at analytics they account for 86% of Sniper Rifle usage in the Crucible – and if we include other low-zoom Sniper Rifles, the number gets even higher.
We’re specifically looking at how zoom translates into ease-of-use for Sniper Rifles. We’re investigating changes that make choosing a Sniper Rifle zoom more of an interesting choice.
Hand Cannons – We’re evaluating the Hand Cannon subfamilies.
As an example, we’re breaking out Aggressive Hand Cannons to let us tune their range independently of the others.
Adaptive Auto Rifles – Auto Rifles in general are highly represented in Crucible, but generally feel balanced. Adaptive Auto Rifles are a little higher, so we’re looking at them.
We’re not rolling back the Season 10 buff, but we’re adjusting the tuning a little to give other Auto Rifle subfamilies a chance to shine.
Moving forward, we plan to make more regular weapon balance changes, we’ll have more to share on cadence and scope later.
In the know
You may have noticed, @BungieHelp on Twitter is freshly verified. If you don’t follow this account, get to it! Player Support, partnered with the Bungie Network Operations Team (BNOC for short), runs this account to keep you up to date on maintenance timelines, bug investigations, and more. Accept no substitute. If you want more details on what’s happening outside of a 280 character limit, read on.
This is their report.
HOTFIX 2.8.1.3
Earlier today, May 21, Hotfix 2.8.1.3 was released to players. This hotfix was designed to resolve the issue with “The Lie” quest not progressing, and the bunker door should now open as expected.
As a result of today’s hotfix, the Felwinter’s Lie Shotgun will not appear in player Collections once acquired. This will be resolved in a future update.
If players are continuing to observe issues with the quest “The Lie”, please report them to the #Help Forum.
ITEMS LEAVING AT END OF SEASON
As the end of Season of the Worthy approaches, several items will be removed from Destiny 2 on June 9, 2020, at the weekly reset. Some of the items leaving at the end of the season include:
Access to the Seraph bunkers on the EDZ, Moon, and Io.
Warmind bits.
4th Horseman Exotic quest.
The Lie quest.
Legendary Lost Sectors.
The Warmind Khanjali Seasonal Artifact.
CURRENT KNOWN ISSUES
While we continue investigating various known issues, here is a list of the latest issues that were reported to us in our #Help Forum:
We are continuing to monitor increases in BEETLE, RABBIT, BEAVER, and ANTEATER error codes.
Some players still have the Guardian Games milestone visible on their characters.
For a full list of emergent issues in Destiny 2, players can review our Known Issues article. Players who observe other issues should report them to our #Help forum.
Clip it
Good play? Clip it. Team wipe? Clip it. Idea for a montage? Write that down, do the thing, clip it. Got a bunch of clips? Splice ‘em. Got a Creation? Submit it.
Movie of the Week: Brightside
Honorable Mention: Wonderful World(s)
If you’re hunting a MOTW emblem, make sure to submit your video to the Creations Page on Bungie.net. Link the Bungie.net accounts of anyone who helped in the video description, or we won’t know where to send your prize!
And once again, we come to the end of a TWAB together. How many have we shared together now? The last few have been filled to the brim with news on upcoming changes, and we’re only a few short weeks until the next Season of Destiny 2.
Wait, what’s that? The Season’s almost over? Sorry, gotta cut this short. I have a Conqueror title to earn.