Commit dfc08077 authored by Wolfgang Rohdewald's avatar Wolfgang Rohdewald
Browse files

more comprehensions

parent 3d2f707b
......@@ -273,7 +273,7 @@ class Board(QGraphicsRectItem, StrMixin):
the next list element.
respect board orientation: Right Arrow should always move right
relative to the screen, not relative to the board"""
return sorted([x for x in self.uiTiles if x.focusable], key=lambda x: x.sortKey(sortDir))
return sorted((x for x in self.uiTiles if x.focusable), key=lambda x: x.sortKey(sortDir))
@property
def hasFocus(self):
......
......@@ -32,7 +32,7 @@ def initRulesets():
predefined.load()
if Options.showRulesets or Options.rulesetName:
from rule import Ruleset
rulesets = dict((x.name, x) for x in Ruleset.selectableRulesets())
rulesets = {x.name: x for x in Ruleset.selectableRulesets()}
if Options.showRulesets:
for name in rulesets:
print(name)
......
......@@ -566,9 +566,8 @@ class KConfigGroup:
items = self.config().items(self.groupName)
except NoSectionError:
return self.__default(name, default)
items = dict((x for x in items if x[0].startswith(name)))
i18nItems = dict(
(x for x in items.items() if x[0].startswith(name + '[')))
items = {x: y for x, y in items if x.startswith(name)}
i18nItems = {x: y for x, y in items.items() if x.startswith(name + '[')}
if i18nItems:
languages = Internal.kajonggrc.group('Locale').readEntry('Language').split(':')
languages = [x.split('_')[0] for x in languages]
......
......@@ -76,7 +76,7 @@ class Message:
return value[0].name
return type(value)([Message.jelly(key, x) for x in value])
elif isinstance(value, dict):
return dict((Message.jelly('key', x[0]), Message.jelly('value', x[1])) for x in value.items())
return {Message.jelly('key', x): Message.jelly('value', y) for x, y in value.items()}
else:
if not isinstance(value, (int, bytes, str, float, type(None))):
raise Exception(
......
......@@ -533,7 +533,7 @@ class PlayingPlayer(Player):
kongs = []
if self == self.game.activePlayer:
# declaring a kong
for tileName in sorted(set([x for x in self._concealedTiles if not x.isBonus])):
for tileName in sorted({x for x in self._concealedTiles if not x.isBonus}):
if self._concealedTiles.count(tileName) == 4:
kongs.append(tileName.kong)
elif self._concealedTiles.count(tileName) == 1 and \
......@@ -794,7 +794,7 @@ class PlayingPlayer(Player):
assert group.islower(), self.visibleTiles
if group in Tile.colors:
if all(x.group == group for x in self.visibleTiles):
suitTiles = set([Tile(group, x) for x in Tile.numbers])
suitTiles = {Tile(group, x) for x in Tile.numbers}
if self.visibleTiles.count(suitTiles) >= 9:
dangerous.append(
(suitTiles, i18n('Player %1 may try a True Color Game', pName)))
......
......@@ -698,8 +698,8 @@ into a situation where you have to pay a penalty"""))
def diff(self, other):
"""return a list of tuples. Every tuple holds one or two rules: tuple[0] is from self, tuple[1] is from other"""
result = []
leftDict = dict((x.name, x) for x in self.allRules)
rightDict = dict((x.name, x) for x in other.allRules)
leftDict = {x.name: x for x in self.allRules}
rightDict = {x.name: x for x in other.allRules}
left = set(leftDict.keys())
right = set(rightDict.keys())
for rule in left & right:
......
......@@ -439,7 +439,7 @@ class StandardMahJongg(MJRule):
continue
singles = {x for x in valueSet
if values.count(x) == 1
and not set([x - 1, x - 2, x + 1, x + 2]) & valueSet}
and not {x - 1, x - 2, x + 1, x + 2} & valueSet}
isolated += len(singles)
if isolated > 1:
# this is not a calling hand
......@@ -525,10 +525,10 @@ class WrigglingSnake(MJRule):
if hand.values.count(1) < 2:
# and the pair of 1 is incomplete too
return set()
return (elements.winds | set([Tile(group, x) for x in range(2, 10)])) \
- set([x.exposed for x in hand.tiles])
return (elements.winds | {Tile(group, x) for x in range(2, 10)}) \
- {x.exposed for x in hand.tiles}
# pair of 1 is not complete
return set([Tile(group, '1')])
return {Tile(group, '1')}
def rearrange(hand, rest):
melds = []
......@@ -724,9 +724,9 @@ class Knitting(MJRule):
return set()
assert len(singleTile) == 1
singleTile = singleTile[0]
otherSuit = (hand.suits - set([singleTile.lowerGroup])).pop()
otherSuit = (hand.suits - {singleTile.lowerGroup}).pop()
otherTile = Tile(otherSuit, singleTile.value).concealed
return set([otherTile])
return {otherTile}
def rearrange(cls, hand, rest):
melds = []
......@@ -797,9 +797,7 @@ class AllPairHonors(MJRule):
return False
if len(set(hand.tiles)) != 7:
return False
tileCounts = list([len([x for x in hand.tiles if x == y])
for y in hand.tiles])
return set(tileCounts) == set([2])
return {len([x for x in hand.tiles if x == y]) for y in hand.tiles} == {2}
def winningTileCandidates(cls, hand):
if not cls.maybeCallingOrWon(hand):
......@@ -878,16 +876,14 @@ class BigFourJoys(RuleCode):
class LittleFourJoys(RuleCode):
def appliesToHand(hand):
lengths = sorted([min(len(x), 3) for x in hand.melds if x.isWindMeld])
lengths = sorted(min(len(x), 3) for x in hand.melds if x.isWindMeld)
return lengths == [2, 3, 3, 3]
class LittleThreeDragons(RuleCode):
def appliesToHand(hand):
lengths = sorted([min(len(x), 3)
for x in hand.melds if x.isDragonMeld])
return lengths == [2, 3, 3]
return sorted(min(len(x), 3) for x in hand.melds if x.isDragonMeld) == [2, 3, 3]
class FourBlessingsHoveringOverTheDoor(RuleCode):
......
......@@ -103,8 +103,7 @@ class SelectPlayers(SelectRuleset):
allNames = set(Players.humanNames.values())
unusedNames = allNames - self.__selectedNames()
with BlockSignals(self.nameWidgets):
used = set([x.currentText()
for x in self.nameWidgets if x.manualSelect])
used = {x.currentText() for x in self.nameWidgets if x.manualSelect}
for combo in self.nameWidgets:
if not combo.manualSelect:
if combo.currentText() in used:
......@@ -117,7 +116,7 @@ class SelectPlayers(SelectRuleset):
combo.clear()
combo.addItems([comboName])
combo.addItems(sorted(
allNames - self.__selectedNames() - set([comboName])))
allNames - self.__selectedNames() - {comboName}))
combo.setCurrentIndex(0)
self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(
len(self.__selectedNames()) == 4)
......
......@@ -119,8 +119,7 @@ class ServerTable(Table, StrMixin):
names = tuple(x.name for x in self.users)
online = tuple(bool(x in onlineNames) for x in names)
if game:
endValues = game.handctr, dict(
(x.wind.char, x.balance) for x in game.players)
endValues = game.handctr, {x.wind.char: x.balance for x in game.players}
else:
endValues = None
return list([
......
......@@ -233,8 +233,7 @@ class Voice(StrMixin):
group = Internal.kajonggrc.group('Locale')
prefLanguages = uniqueList(
':'.join(['local', str(group.readEntry('Language')), 'en_US']).split(':'))
prefLanguages = dict((x[1], x[0])
for x in enumerate(prefLanguages))
prefLanguages = {x: y for x, y in enumerate(prefLanguages)}
result = sorted(
result, key=lambda x: prefLanguages.get(x.language(), 9999))
if Debug.sound:
......
......@@ -384,12 +384,11 @@ class TableList(QWidget):
"""copy chatWindows from the old table list which will be
thrown away"""
if self.view.model():
chatWindows = dict((x.tableid, x.chatWindow)
for x in self.view.model().tables)
chatWindows = {x.tableid: x.chatWindow for x in self.view.model().tables}
unusedWindows = {x.chatWindow for x in self.view.model().tables}
for table in tables:
table.chatWindow = chatWindows.get(table.tableid, None)
unusedWindows -= set([table.chatWindow])
unusedWindows -= {table.chatWindow}
for unusedWindow in unusedWindows:
if unusedWindow:
unusedWindow.hide()
......
......@@ -273,7 +273,7 @@ class TileList(list):
values = {x.value for x in self if x.group == group}
chows = []
for offsets in [(0, 1, 2), (-2, -1, 0), (-1, 0, 1)]:
subset = set([tile.value + x for x in offsets])
subset = {tile.value + x for x in offsets}
if subset <= values:
chow = TileList(Tile(group, x) for x in sorted(subset))
if chow not in chows:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment